Skip to content

Conversation

@marcromeyn
Copy link
Contributor

I noticed that this command in nemo is broken currently, this PR should fix it:

╭───────────────────────────────────────────────────── Traceback (most recent call last) ──────────────────────────────────────────────────────╮
│ /usr/local/bin/nemo:8 in <module>                                                                                                            │
│                                                                                                                                              │
│   5 from nemo_run.__main__ import app                                                                                                        │
│   6 if __name__ == '__main__':                                                                                                               │
│   7 │   sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])                                                                     │
│ ❱ 8 │   sys.exit(app())                                                                                                                      │
│   9                                                                                                                                          │
│                                                                                                                                              │
│ ╭─────────────────────────── locals ────────────────────────────╮                                                                            │
│ │ app = <typer.main.Typer object at 0x7fa8aee7be30>             │                                                                            │
│ │  re = <module 're' from '/usr/lib/python3.12/re/__init__.py'> │                                                                            │
│ │ sys = <module 'sys' (built-in)>                               │                                                                            │
│ ╰───────────────────────────────────────────────────────────────╯                                                                            │
│                                                                                                                                              │
│ /usr/local/lib/python3.12/dist-packages/typer/main.py:340 in __call__                                                                        │
│                                                                                                                                              │
│ /usr/local/lib/python3.12/dist-packages/typer/main.py:323 in __call__                                                                        │
│                                                                                                                                              │
│ /usr/local/lib/python3.12/dist-packages/click/core.py:1161 in __call__                                                                       │
│                                                                                                                                              │
│ /usr/local/lib/python3.12/dist-packages/typer/core.py:743 in main                                                                            │
│                                                                                                                                              │
│ /usr/local/lib/python3.12/dist-packages/typer/core.py:198 in _main                                                                           │
│                                                                                                                                              │
│ /usr/local/lib/python3.12/dist-packages/click/core.py:1697 in invoke                                                                         │
│                                                                                                                                              │
│ /usr/local/lib/python3.12/dist-packages/click/core.py:1695 in invoke                                                                         │
│                                                                                                                                              │
│ /usr/local/lib/python3.12/dist-packages/click/core.py:949 in make_context                                                                    │
│                                                                                                                                              │
│ /usr/local/lib/python3.12/dist-packages/click/core.py:1417 in parse_args                                                                     │
│                                                                                                                                              │
│ /usr/local/lib/python3.12/dist-packages/click/core.py:2403 in handle_parse_result                                                            │
│                                                                                                                                              │
│ /usr/local/lib/python3.12/dist-packages/click/core.py:2365 in process_value                                                                  │
│                                                                                                                                              │
│ /usr/local/lib/python3.12/dist-packages/click/decorators.py:550 in show_help                                                                 │
│                                                                                                                                              │
│ /usr/local/lib/python3.12/dist-packages/click/core.py:711 in get_help                                                                        │
│                                                                                                                                              │
│ /usr/local/lib/python3.12/dist-packages/click/core.py:1334 in get_help                                                                       │
│                                                                                                                                              │
│ /opt/NeMo-Run/src/nemo_run/cli/api.py:1525 in format_help                                                                                    │
│                                                                                                                                              │
│   1522 │   │   │   │   )                                                                                                                     │
│   1523 │   │   │   )                                                                                                                         │
│   1524 │   │                                                                                                                                 │
│ ❱ 1525 │   │   self._entrypoint.help(console, with_docs=sys.argv[-1] in ("--docs", "-d"))                                                    │
│   1526 │   │                                                                                                                                 │
│   1527 │   │   return out                                                                                                                    │
│   1528                                                                                                                                       │
│                                                                                                                                              │
│ ╭─────────────────────────────── locals ────────────────────────────────╮                                                                    │
│ │ box_style = None                                                      │                                                                    │
│ │   console = <console width=144 ColorSystem.TRUECOLOR>                 │                                                                    │
│ │       ctx = <click.core.Context object at 0x7fa52459cc20>             │                                                                    │
│ │ formatter = <click.formatting.HelpFormatter object at 0x7fa5243c43b0> │                                                                    │
│ │       out = None                                                      │                                                                    │
│ │      self = <CLITaskCommand generate>                                 │                                                                    │
│ │     table = <rich.table.Table object at 0x7fa524771df0>               │                                                                    │
│ ╰───────────────────────────────────────────────────────────────────────╯                                                                    │
│                                                                                                                                              │
│ /opt/NeMo-Run/src/nemo_run/cli/api.py:1471 in help                                                                                           │
│                                                                                                                                              │
│   1468 │   def help(self, console=Console(), with_docs: bool = True):                                                                        │
│   1469 │   │   import nemo_run as run                                                                                                        │
│   1470 │   │                                                                                                                                 │
│ ❱ 1471 │   │   run.help(self.fn, console=console, with_docs=with_docs)                                                                       │
│   1472 │                                                                                                                                     │
│   1473 │   @property                                                                                                                         │
│   1474 │   def path(self):                                                                                                                   │
│                                                                                                                                              │
│ ╭─────────────────────────────────── locals ────────────────────────────────────╮                                                            │
│ │   console = <console width=144 ColorSystem.TRUECOLOR>                         │                                                            │
│ │       run = <module 'nemo_run' from '/opt/NeMo-Run/src/nemo_run/__init__.py'> │                                                            │
│ │      self = <nemo_run.cli.api.Entrypoint object at 0x7fa53e98b980>            │                                                            │
│ │ with_docs = False                                                             │                                                            │
│ ╰───────────────────────────────────────────────────────────────────────────────╯                                                            │
│                                                                                                                                              │
│ /opt/NeMo-Run/src/nemo_run/help.py:279 in help                                                                                               │
│                                                                                                                                              │
│   276 │   along with all factories registered for the Callable's args.                                                                       │
│   277 │   Optionally outputs docstrings as well.                                                                                             │
│   278 │   """                                                                                                                                │
│ ❱ 279 │   return help_for_callable(entity, with_docs=with_docs, namespace=namespace)                                                         │
│   280                                                                                                                                        │
│   281                                                                                                                                        │
│   282 def _get_module(class_obj) -> str:                                                                                                     │
│                                                                                                                                              │
│ ╭─────────────────────── locals ────────────────────────╮                                                                                    │
│ │   console = <console width=144 ColorSystem.TRUECOLOR> │                                                                                    │
│ │ namespace = None                                      │                                                                                    │
│ │ with_docs = False                                     │                                                                                    │
│ ╰───────────────────────────────────────────────────────╯                                                                                    │
│                                                                                                                                              │
│ /opt/NeMo-Run/src/nemo_run/help.py:134 in help_for_callable                                                                                  │
│                                                                                                                                              │
│   131 │                                                                                                                                      │
│   132 │   for arg_name, param in params.items():                                                                                             │
│   133 │   │   arg_text = Text(arg_name, style="bold magenta")                                                                                │
│ ❱ 134 │   │   type_text = Text.from_markup(class_to_str(param.annotation), style="bold cyan")                                                │
│   135 │   │                                                                                                                                  │
│   136 │   │   default_value_text = Text("")                                                                                                  │
│   137 │   │   default_value = param.default                                                                                                  │
│                                                                                                                                              │
│ ╭───────────────────────────────────────────────────────────────── locals ─────────────────────────────────────────────────────────────────╮ │
│ │           arg_name = 'prompts'                                                                                                           │ │
│ │           arg_text = <text 'prompts' [] 'bold magenta'>                                                                                  │ │
│ │          box_style = None                                                                                                                │ │
│ │ default_value_text = <text '' [] ''>                                                                                                     │ │
│ │  display_executors = True                                                                                                                │ │
│ │          namespace = None                                                                                                                │ │
│ │              param = <Parameter "prompts: Optional[list[str]] = None">                                                                   │ │
│ │             params = mappingproxy({                                                                                                      │ │
│ │                      │   'path': <Parameter "path: Union[pathlib.Path, str]">,                                                           │ │
│ │                      │   'trainer': <Parameter "trainer: nemo.lightning.pytorch.trainer.Trainer">,                                       │ │
│ │                      │   'prompts': <Parameter "prompts: Optional[list[str]] = None">,                                                   │ │
│ │                      │   'encoder_prompts': <Parameter "encoder_prompts: Optional[list[str]] = None">,                                   │ │
│ │                      │   'input_dataset': <Parameter "input_dataset: Union[lightning.pytorch.core.datamodule.LightningDataModule, str,   │ │
│ │                      NoneType] = None">,                                                                                                 │ │
│ │                      │   'params_dtype': <Parameter "params_dtype: torch.dtype = torch.bfloat16">,                                       │ │
│ │                      │   'add_BOS': <Parameter "add_BOS: bool = False">,                                                                 │ │
│ │                      │   'max_batch_size': <Parameter "max_batch_size: int = 4">,                                                        │ │
│ │                      │   'random_seed': <Parameter "random_seed: Optional[int] = None">,                                                 │ │
│ │                      │   'inference_batch_times_seqlen_threshold': <Parameter "inference_batch_times_seqlen_threshold: int = 1000">,     │ │
│ │                      │   ... +3                                                                                                          │ │
│ │                      })                                                                                                                  │ │
│ │                sig = <Signature (path: Union[pathlib.Path, str], trainer: nemo.lightning.pytorch.trainer.Trainer, prompts:               │ │
│ │                      Optional[list[str]] = None, encoder_prompts: Optional[list[str]] = None, input_dataset:                             │ │
│ │                      Union[lightning.pytorch.core.datamodule.LightningDataModule, str, NoneType] = None, params_dtype: torch.dtype =     │ │
│ │                      torch.bfloat16, add_BOS: bool = False, max_batch_size: int = 4, random_seed: Optional[int] = None,                  │ │
│ │                      inference_batch_times_seqlen_threshold: int = 1000, inference_params: Optional[ForwardRef('CommonInferenceParams')] │ │
│ │                      = None, text_only: bool = False, output_path: Union[pathlib.Path, str, NoneType] = None) ->                         │ │
│ │                      list[typing.Union[ForwardRef('InferenceRequest'), str]]>                                                            │ │
│ │              table = <rich.table.Table object at 0x7fa5246aa660>                                                                         │ │
│ │          type_text = <text 'nm.Trainer' [] 'bold cyan'>                                                                                  │ │
│ │          with_docs = False                                                                                                               │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                                                                              │
│ /opt/NeMo-Run/src/nemo_run/help.py:234 in class_to_str                                                                                       │
│                                                                                                                                              │
│   231 │   if hasattr(class_obj, "__origin__"):                                                 ╭──────────────── locals ────────────────╮    │
│   232 │   │   # Special handling for Optional types which are represented as Union[X, NoneType │ class_obj = typing.Optional[list[str]] │    │
│   233 │   │   if class_obj._name == "Optional":                                                ╰────────────────────────────────────────╯    │
│ ❱ 234 │   │   │   args = class_to_str(typing.get_args(class_obj)[0])                                                                         │
│   235 │   │   │   return f"Optional[{args}]"                                                                                                 │
│   236 │   │   else:                                                                                                                          │
│   237 │   │   │   # Get the base type                                                                                                        │
│                                                                                                                                              │
│ /opt/NeMo-Run/src/nemo_run/help.py:233 in class_to_str                                                                                       │
│                                                                                                                                              │
│   230 def class_to_str(class_obj):                                                             ╭─────── locals ────────╮                     │
│   231 │   if hasattr(class_obj, "__origin__"):                                                 │ class_obj = list[str] │                     │
│   232 │   │   # Special handling for Optional types which are represented as Union[X, NoneType ╰───────────────────────╯                     │
│ ❱ 233 │   │   if class_obj._name == "Optional":                                                                                              │
│   234 │   │   │   args = class_to_str(typing.get_args(class_obj)[0])                                                                         │
│   235 │   │   │   return f"Optional[{args}]"                                                                                                 │
│   236 │   │   else:                                                                                                                          │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
AttributeError: type object 'list' has no attribute '_name'

except (AttributeError, TypeError):
# If typing helpers fail, we'll handle through other means
origin = None
args = []

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable args is not used.

Copilot Autofix

AI 10 months ago

To fix the problem, we need to remove the assignment of the args variable on line 251. Since the right-hand side of the assignment (typing.get_args(class_obj)) does not have any side effects, we can safely remove the entire line without affecting the functionality of the code. This will eliminate the unused local variable and clean up the code.

Suggested changeset 1
nemo_run/help.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/nemo_run/help.py b/nemo_run/help.py
--- a/nemo_run/help.py
+++ b/nemo_run/help.py
@@ -250,3 +250,3 @@
         origin = typing.get_origin(class_obj)
-        args = typing.get_args(class_obj)
+
     except (AttributeError, TypeError):
EOF
@@ -250,3 +250,3 @@
origin = typing.get_origin(class_obj)
args = typing.get_args(class_obj)

except (AttributeError, TypeError):
Copilot is powered by AI and may make mistakes. Always verify output.
@marcromeyn marcromeyn committed this autofix suggestion 10 months ago.
marcromeyn and others added 12 commits April 17, 2025 10:01
Signed-off-by: Marc Romeyn <mromeijn@nvidia.com>
Signed-off-by: Marc Romeyn <mromeijn@nvidia.com>
Signed-off-by: Marc Romeyn <mromeijn@nvidia.com>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Signed-off-by: Marc Romeyn <marcromeyn@gmail.com>
Signed-off-by: Marc Romeyn <marcromeyn@gmail.com>
Signed-off-by: Marc Romeyn <marcromeyn@gmail.com>
Signed-off-by: Marc Romeyn <marcromeyn@gmail.com>
Signed-off-by: Marc Romeyn <mromeijn@nvidia.com>
Signed-off-by: Marc Romeyn <mromeijn@nvidia.com>
Signed-off-by: Marc Romeyn <mromeijn@nvidia.com>
Signed-off-by: Marc Romeyn <mromeijn@nvidia.com>
Signed-off-by: Marc Romeyn <mromeijn@nvidia.com>
Signed-off-by: Marc Romeyn <mromeijn@nvidia.com>
Signed-off-by: Marc Romeyn <mromeijn@nvidia.com>
Signed-off-by: Marc Romeyn <mromeijn@nvidia.com>
Signed-off-by: Marc Romeyn <mromeijn@nvidia.com>
Signed-off-by: Marc Romeyn <mromeijn@nvidia.com>
@snowmanwwg
Copy link

relate to #178 which is merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants