| name | linting-and-formatting |
| description | Code style and quality rules for NeMo AutoModel — ruff configuration, naming conventions, type hints, docstrings, copyright headers, and the code review checklist. |
| when_to_use | Writing or reviewing code for style compliance, fixing ruff errors, understanding type hint or docstring conventions, copyright header questions, or pre-commit failures. |
Linting and Formatting
Single source of truth for code style in NeMo AutoModel. Read this before
writing new code or reviewing PRs.
Formatting and Linting
Run before every commit:
ruff format .
ruff check --fix .
To check without modifying files:
ruff format --check .
ruff check .
To lint a single file or directory:
ruff format nemo_automodel/components/models/llama/model.py
ruff check --fix nemo_automodel/components/models/llama/
What ruff enforces (from pyproject.toml)
| Rule | ID | Description |
|---|
| Line length | — | 120 characters (formatter) |
| Quote style | — | Double quotes |
| Unused imports | F401 | Auto-removed by --fix (ignored in __init__.py) |
| Unused variables | F841 | Auto-removed by --fix |
| Undefined names | F821 | Error |
| f-string without placeholders | F541 | Error |
| Import sorting | I | isort-compatible ordering, auto-fixed |
| Docstring convention | D101/D103 | Google style (currently ignored — selected then suppressed) |
| No pickle | S301/S403 | Security: forbids pickle.load |
| Ambiguous variable names | E741 | Error (e.g., l, O, I) |
Tests (tests/) are excluded from lint checks. Docstring rules (D) are
also relaxed in test files.
Type Hints
Required on all public API functions and methods.
- Use
T | None instead of Optional[T]
- Use
X | Y instead of Union[X, Y]
- Use built-in generics (
list, dict, tuple) instead of typing equivalents
Docstrings
Google-style where docstrings are added:
def build_model(config: dict) -> torch.nn.Module:
"""Instantiate and shard the model from config.
Args:
config: Mapping with _target_ and model hyperparameters.
Returns:
Fully initialized model ready for distributed training.
"""
NVIDIA Copyright Header
Every Python file must start with the NVIDIA copyright block. Do not remove or
modify it. Use the current year (2026).
Additional Style Conventions
- Explicit over implicit. Inline logic where possible; avoid hiding behavior
behind unnecessary layers of indirection.
- No speculative abstractions. Do not add features, parameters, or
generalization beyond what is explicitly asked for.
- Optional dependencies must be guarded with
safe_import() from
nemo_automodel.shared.import_utils. Never let an optional import crash
module loading.
- Components must not import each other — enforced by
import-linter
(see pyproject.toml).
Code Review Checklist
- Copyright header present on all new Python files
- Type hints on all public functions and methods
- Docstrings on public classes and functions (Google style)
- Double quotes for strings
- No bare
print() — use logging.getLogger(__name__)
- No commented-out code without explanation
- Optional imports guarded with
safe_import()
- No cross-component imports between
components/ subdirectories