linting-and-formatting
$
npx mdskill add NVIDIA/Megatron-LM/linting-and-formattingEnforce code quality and style for Megatron-LM projects.
- Fixes linting errors and autoformats Python code automatically.
- Integrates ruff, black, isort, pylint, and mypy tools.
- Executes autoformat.sh scripts with configurable check modes.
- Applies strict rules for type hints, naming, and line length.
SKILL.md
.github/skills/linting-and-formattingView on GitHub ↗
--- name: linting-and-formatting description: Linting and formatting for Megatron-LM. Covers running autoformat.sh, tools (ruff, black, isort, pylint, mypy), and code style rules. when_to_use: Running linting or autoformat; fixing style violations before a PR; 'pre-commit fails', 'ruff error', 'isort', 'mypy', 'style violation', 'how do I format', 'autoformat.sh'. --- # Linting and Formatting --- ## Running the Formatter Run before opening a PR: ```bash # Check mode (no changes applied) BASE_REF=main CHECK_ONLY=true SKIP_DOCS=false bash tools/autoformat.sh # Fix mode BASE_REF=main CHECK_ONLY=false bash tools/autoformat.sh ``` Tools invoked: `black`, `isort`, `pylint`, `ruff`, `mypy`. --- ## Import Ordering After editing imports in any Python files, always run `uv run isort` on those files before committing: ```bash uv run isort <file1>.py <file2>.py ``` --- ## Setting Up the Linting Group Inside the container: ```bash uv sync --locked --only-group linting ``` This installs `ruff`, `black`, `isort`, `pylint` — the same tools used by `tools/autoformat.sh` and CI's `linting` job. --- ## Code Style Rules - **Type hints**: required on all public API functions. Use `X | None`, not `Optional[X]`. - **Docstrings**: Google-style on all public classes and functions. - **Naming**: follow Python conventions — `snake_case` for functions and variables, `PascalCase` for classes. - **Line length**: 119 characters (configured in `pyproject.toml`). - **No bare `except`**: always catch specific exception types.
More from NVIDIA/Megatron-LM
- build-and-dependencyContainer-based dev environment setup and dependency management for Megatron-LM. Covers acquiring and launching the CI container, uv package management, and updating uv.lock.
- cicdCI/CD reference for Megatron-LM. Covers CI pipeline structure, PR scope labels, triggering internal GitLab CI, and CI failure investigation.
- create-issueInvestigate a failing GitHub Actions run or job and create a GitHub issue for the failure.
- nightly-syncDomain knowledge for the nightly main-to-dev sync workflow. Covers merge strategy, CI architecture, failure investigation, and known issues.
- onboard-gb200-1node-testsOnboard 1-node GitHub MR functional tests for GB200 from existing mr-scoped 2-node tests.
- respond-to-issueResearch and draft a response to a GitHub issue or question from an external contributor.
- run-on-slurmHow to launch distributed Megatron-LM training jobs on a SLURM cluster. Covers a minimal sbatch skeleton, environment-variable setup for torch.distributed.run, CUDA_DEVICE_MAX_CONNECTIONS rules across hardware and parallelism modes, container conventions, monitoring, and per-rank failure diagnosis.
- split-prSplit a PR into multiple PRs to reduce the number of required CODEOWNERS reviewer groups.
- testingTest system for Megatron-LM. Covers test layout, recipe YAML structure, adding and running unit and functional tests, golden values, marker filters, and CI parity.