transformers - 💡(How to fix) Fix [Bug] Official Nemotron example broken [2 pull requests]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Error Message

(nemotron-explorations) shadeform@brev-i10j30gd7:/ephemeral/projects/nemotron-explorations$ python main.py Loading weights: 100%|██████████████████████████████████████████████████████████| 6243/6243 [00:01<00:00, 6110.90it/s] [transformers] Both max_new_tokens (=256) and max_length(=20) seem to have been set. max_new_tokens will take precedence. Please refer to the documentation for more information. (https://huggingface.co/docs/transformers/main/en/main_classes/text_generation) Traceback (most recent call last): File "/ephemeral/projects/nemotron-explorations/main.py", line 7, in <module> pipe(messages) File "/ephemeral/projects/nemotron-explorations/.venv/lib/python3.12/site-packages/transformers/pipelines/text_generation.py", line 299, in call return super().call(text_inputs, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/ephemeral/projects/nemotron-explorations/.venv/lib/python3.12/site-packages/transformers/pipelines/base.py", line 1266, in call return self.run_single(inputs, preprocess_params, forward_params, postprocess_params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/ephemeral/projects/nemotron-explorations/.venv/lib/python3.12/site-packages/transformers/pipelines/base.py", line 1273, in run_single model_outputs = self.forward(model_inputs, **forward_params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/ephemeral/projects/nemotron-explorations/.venv/lib/python3.12/site-packages/transformers/pipelines/base.py", line 1165, in forward model_outputs = self._forward(model_inputs, **forward_params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/ephemeral/projects/nemotron-explorations/.venv/lib/python3.12/site-packages/transformers/pipelines/text_generation.py", line 403, in _forward output = self.model.generate(input_ids=input_ids, attention_mask=attention_mask, **generate_kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/ephemeral/projects/nemotron-explorations/.venv/lib/python3.12/site-packages/torch/utils/_contextlib.py", line 124, in decorate_context return func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/ephemeral/projects/nemotron-explorations/.venv/lib/python3.12/site-packages/transformers/generation/utils.py", line 2582, in generate result = decoding_method( ^^^^^^^^^^^^^^^^ File "/ephemeral/projects/nemotron-explorations/.venv/lib/python3.12/site-packages/transformers/generation/utils.py", line 2782, in _sample outputs = self._prefill( ^^^^^^^^^^^^^^ File "/ephemeral/projects/nemotron-explorations/.venv/lib/python3.12/site-packages/transformers/generation/utils.py", line 3822, in _prefill model_inputs = self.prepare_inputs_for_generation( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/ephemeral/models/hf/modules/transformers_modules/nvidia/NVIDIA_hyphen_Nemotron_hyphen_3_hyphen_Nano_hyphen_30B_hyphen_A3B_hyphen_BF16/cbd3fa9f933d55ef16a84236559f4ee2a0526848/modeling_nemotron_h.py", line 1633, in prepare_inputs_for_generation or cache_position[-1] >= input_ids.shape[1] # Exception 3 ~~~~~~~~~~~~~~^^^^ TypeError: 'NoneType' object is not subscriptable

Fix Action

Fixed

Code Example

[project]
name = "nemotron-explorations"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
    "torch>=2.12.0",
    "torchvision>=0.27.0",
    "transformers==5.10.2",
    "mamba-ssm[causal-conv1d]",
]

[tool.uv.sources]
torch = { index = "pytorch-cu126" }
torchvision = { index = "pytorch-cu126" }

[tool.uv]
no-build-isolation-package = ["mamba-ssm"]

[[tool.uv.index]]
name = "pytorch-cu126"
url = "https://download.pytorch.org/whl/cu126"
explicit = true

---

from transformers import pipeline

pipe = pipeline("text-generation", model="nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B-BF16", trust_remote_code=True)
messages = [
    {"role": "user", "content": "Who are you?"},
]
pipe(messages)

---

(nemotron-explorations) shadeform@brev-i10j30gd7:/ephemeral/projects/nemotron-explorations$ python main.py
Loading weights: 100%|██████████████████████████████████████████████████████████| 6243/6243 [00:01<00:00, 6110.90it/s]
[transformers] Both `max_new_tokens` (=256) and `max_length`(=20) seem to have been set. `max_new_tokens` will take precedence. Please refer to the documentation for more information. (https://huggingface.co/docs/transformers/main/en/main_classes/text_generation)
Traceback (most recent call last):
  File "/ephemeral/projects/nemotron-explorations/main.py", line 7, in <module>
    pipe(messages)
  File "/ephemeral/projects/nemotron-explorations/.venv/lib/python3.12/site-packages/transformers/pipelines/text_generation.py", line 299, in __call__
    return super().__call__(text_inputs, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/ephemeral/projects/nemotron-explorations/.venv/lib/python3.12/site-packages/transformers/pipelines/base.py", line 1266, in __call__
    return self.run_single(inputs, preprocess_params, forward_params, postprocess_params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/ephemeral/projects/nemotron-explorations/.venv/lib/python3.12/site-packages/transformers/pipelines/base.py", line 1273, in run_single
    model_outputs = self.forward(model_inputs, **forward_params)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/ephemeral/projects/nemotron-explorations/.venv/lib/python3.12/site-packages/transformers/pipelines/base.py", line 1165, in forward
    model_outputs = self._forward(model_inputs, **forward_params)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/ephemeral/projects/nemotron-explorations/.venv/lib/python3.12/site-packages/transformers/pipelines/text_generation.py", line 403, in _forward
    output = self.model.generate(input_ids=input_ids, attention_mask=attention_mask, **generate_kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/ephemeral/projects/nemotron-explorations/.venv/lib/python3.12/site-packages/torch/utils/_contextlib.py", line 124, in decorate_context
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/ephemeral/projects/nemotron-explorations/.venv/lib/python3.12/site-packages/transformers/generation/utils.py", line 2582, in generate
    result = decoding_method(
             ^^^^^^^^^^^^^^^^
  File "/ephemeral/projects/nemotron-explorations/.venv/lib/python3.12/site-packages/transformers/generation/utils.py", line 2782, in _sample
    outputs = self._prefill(
              ^^^^^^^^^^^^^^
  File "/ephemeral/projects/nemotron-explorations/.venv/lib/python3.12/site-packages/transformers/generation/utils.py", line 3822, in _prefill
    model_inputs = self.prepare_inputs_for_generation(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/ephemeral/models/hf/modules/transformers_modules/nvidia/NVIDIA_hyphen_Nemotron_hyphen_3_hyphen_Nano_hyphen_30B_hyphen_A3B_hyphen_BF16/cbd3fa9f933d55ef16a84236559f4ee2a0526848/modeling_nemotron_h.py", line 1633, in prepare_inputs_for_generation
    or cache_position[-1] >= input_ids.shape[1]  # Exception 3
       ~~~~~~~~~~~~~~^^^^
TypeError: 'NoneType' object is not subscriptable
RAW_BUFFERClick to expand / collapse

System Info

transformers env fails with: NameError: name 'CompletionCreateParamsStreaming' is not defined

but my pyproject if fairly simple (and python and cuda and packages are in here):

[project]
name = "nemotron-explorations"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
    "torch>=2.12.0",
    "torchvision>=0.27.0",
    "transformers==5.10.2",
    "mamba-ssm[causal-conv1d]",
]

[tool.uv.sources]
torch = { index = "pytorch-cu126" }
torchvision = { index = "pytorch-cu126" }

[tool.uv]
no-build-isolation-package = ["mamba-ssm"]

[[tool.uv.index]]
name = "pytorch-cu126"
url = "https://download.pytorch.org/whl/cu126"
explicit = true

Who can help?

@suhara @ArthurZucker

Information

  • The official example scripts
  • My own modified scripts

Tasks

  • An officially supported task in the examples folder (such as GLUE/SQuAD, ...)
  • My own task or dataset (give details below)

Reproduction

Consider:

from transformers import pipeline

pipe = pipeline("text-generation", model="nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B-BF16", trust_remote_code=True)
messages = [
    {"role": "user", "content": "Who are you?"},
]
pipe(messages)

then the traceback:

(nemotron-explorations) shadeform@brev-i10j30gd7:/ephemeral/projects/nemotron-explorations$ python main.py
Loading weights: 100%|██████████████████████████████████████████████████████████| 6243/6243 [00:01<00:00, 6110.90it/s]
[transformers] Both `max_new_tokens` (=256) and `max_length`(=20) seem to have been set. `max_new_tokens` will take precedence. Please refer to the documentation for more information. (https://huggingface.co/docs/transformers/main/en/main_classes/text_generation)
Traceback (most recent call last):
  File "/ephemeral/projects/nemotron-explorations/main.py", line 7, in <module>
    pipe(messages)
  File "/ephemeral/projects/nemotron-explorations/.venv/lib/python3.12/site-packages/transformers/pipelines/text_generation.py", line 299, in __call__
    return super().__call__(text_inputs, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/ephemeral/projects/nemotron-explorations/.venv/lib/python3.12/site-packages/transformers/pipelines/base.py", line 1266, in __call__
    return self.run_single(inputs, preprocess_params, forward_params, postprocess_params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/ephemeral/projects/nemotron-explorations/.venv/lib/python3.12/site-packages/transformers/pipelines/base.py", line 1273, in run_single
    model_outputs = self.forward(model_inputs, **forward_params)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/ephemeral/projects/nemotron-explorations/.venv/lib/python3.12/site-packages/transformers/pipelines/base.py", line 1165, in forward
    model_outputs = self._forward(model_inputs, **forward_params)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/ephemeral/projects/nemotron-explorations/.venv/lib/python3.12/site-packages/transformers/pipelines/text_generation.py", line 403, in _forward
    output = self.model.generate(input_ids=input_ids, attention_mask=attention_mask, **generate_kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/ephemeral/projects/nemotron-explorations/.venv/lib/python3.12/site-packages/torch/utils/_contextlib.py", line 124, in decorate_context
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/ephemeral/projects/nemotron-explorations/.venv/lib/python3.12/site-packages/transformers/generation/utils.py", line 2582, in generate
    result = decoding_method(
             ^^^^^^^^^^^^^^^^
  File "/ephemeral/projects/nemotron-explorations/.venv/lib/python3.12/site-packages/transformers/generation/utils.py", line 2782, in _sample
    outputs = self._prefill(
              ^^^^^^^^^^^^^^
  File "/ephemeral/projects/nemotron-explorations/.venv/lib/python3.12/site-packages/transformers/generation/utils.py", line 3822, in _prefill
    model_inputs = self.prepare_inputs_for_generation(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/ephemeral/models/hf/modules/transformers_modules/nvidia/NVIDIA_hyphen_Nemotron_hyphen_3_hyphen_Nano_hyphen_30B_hyphen_A3B_hyphen_BF16/cbd3fa9f933d55ef16a84236559f4ee2a0526848/modeling_nemotron_h.py", line 1633, in prepare_inputs_for_generation
    or cache_position[-1] >= input_ids.shape[1]  # Exception 3
       ~~~~~~~~~~~~~~^^^^
TypeError: 'NoneType' object is not subscriptable

Expected behavior

text generation

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

text generation

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING