Linting and formatting for Megatron-LM. Covers running autoformat.sh, tools (ruff, black, isort, pylint, mypy), and code style rules.
This NVIDIA skill is a concise reference for linting and formatting code in the Megatron-LM project. It solves the common friction of getting a large machine-learning codebase to pass its style and CI checks before a pull request: it documents the single autoformat entrypoint, the exact tools involved, and the project's code-style rules so contributors do not have to reverse-engineer the pipeline.
The guidance shows how to run tools/autoformat.sh in both check mode (no changes) and fix mode via BASE_REF and CHECK_ONLY environment variables, and lists the tools it invokes: black, isort, pylint, ruff, and mypy. It explains how to set up the linting dependency group inside the container with uv sync --locked --only-group linting, how to re-run isort on edited files before committing, and the concrete style rules the project enforces: type hints on public APIs using the X | None form, Google-style docstrings, snake_case/PascalCase naming, a 119-character line length configured in pyproject.toml, and no bare except clauses.
It targets contributors and engineers working on Megatron-LM (or similar Megatron-Core codebases) who need to fix style violations, resolve pre-commit or ruff/mypy errors, and format code ahead of a PR. All documented operations are read-only or formatting-only invocations of standard, well-known Python developer tooling, and the skill's published benchmark reports a passing evaluation. It is a lightweight, guidance-focused convention reference rather than a code-generating or system-modifying tool.
black, isort, pylint, ruff, and mypy, all invoked through tools/autoformat.sh, the same tools used by the CI linting job.
Run the script in check mode: BASE_REF=main CHECK_ONLY=true SKIP_DOCS=false bash tools/autoformat.sh. Use CHECK_ONLY=false to apply fixes.
Inside the container, run uv sync --locked --only-group linting, which installs ruff, black, isort, and pylint.
Type hints on all public APIs using X | None (not Optional[X]), Google-style docstrings, snake_case functions and PascalCase classes, a 119-character line length, and no bare except.
Yes, it is written for Megatron-LM's toolchain and pyproject configuration, though the general tools apply broadly to Python projects.
Quick Setup:
.claude/skills/Repository
nvidia/skills