Skip to main content
skill CX Codex

mcore-testing — Claude Code skill: Megatron-LM tests

A skill that maps out the Megatron-LM test system: test layout, recipe YAML, golden values, and how to run unit tests locally.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add NVIDIA/skills --skill mcore-testing -a claude-code
Open on GitHub

What mcore-testing does

The skill documents how testing works in Megatron-LM and answers questions like how to add a test, why pytest fails, and where golden values live. It covers the tests/ directory layout, the structure of recipe YAML files, the steps for adding unit and functional tests, pytest markers, and reproducing a CI failure on your own machine.

Unit tests initialize a torch.distributed group, so every run needs GPU access and goes through torch.distributed.run. A full suite run looks like uv run python -m torch.distributed.run --nproc-per-node 8 -m pytest -q tests/unit_tests. Narrow it down with -k for a name substring or with marker filters such as -m "not flaky and not flaky_in_dev". To match a CI bucket exactly, use tests/unit_tests/run_ci_test.sh.

Functional tests sit in tests/functional_tests/test_cases/{model}/{test_case}/ and need a model_config.yaml plus a recipe entry. Once a run passes, golden values are pulled with download_golden_values.py and committed. One thing to watch: conftest.py looks for test data under /opt/data and tries to download it when missing, so outside the canonical container you supply the data yourself or skip the tests that depend on it.

What it helps with

  • figure out the tests/ layout and where a new test belongs
  • write a recipe YAML for a functional test with all required fields
  • reproduce a failing CI bucket locally
  • download and commit golden values after a passing run
  • disable a flaky test without deleting it from the recipe

Example prompts for the agent

  • how do I add a unit test under tests/unit_tests?
  • pytest fails on the model test, help me reproduce it locally
  • write a recipe YAML for a new functional test

How to install mcore-testing

1Skills CLI (Vercel)

npx skills add NVIDIA/skills --skill mcore-testing -a claude-code

2Manually: put the files in place

~/.claude/skills/mcore-testing/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/mcore-testing/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about mcore-testing

How do I install mcore-testing in Claude?

Run npx skills add NVIDIA/skills --skill mcore-testing -a claude-code. The skill lands at ~/.claude/skills/mcore-testing/SKILL.md.

What does mcore-testing do?

It covers the Megatron-LM test system: test layout, recipe YAML structure, adding and running unit and functional tests, golden values, marker filters, and CI parity.

How do I disable a test without deleting it?

In a recipe YAML, suffix the scope value with -broken, for example scope: [mr-github-broken]. For unit tests, use the @pytest.mark.flaky_in_dev or @pytest.mark.flaky markers instead.

Source text

SKILL.md · Apache-2.0
---
name: mcore-testing
description: Test system for Megatron-LM. Covers test layout, recipe YAML structure, adding and running unit and functional tests, golden values, marker filters, and CI parity.
license: Apache-2.0
when_to_use: Adding or running a unit or functional test; understanding the test layout; writing a recipe YAML; downloading or updating golden values; reproducing a test failure locally; 'how do I add a test', 'run unit tests', 'pytest fails', 'test layout', 'golden values', 'recipe YAML', 'marker filter'.
metadata:
  author: Philip Petrakian <[email protected]>
---

# Testing Guide

---

## Answer-First Testing Facts

For questions about disabling tests without deleting them:

- Functional recipe entries stay in YAML; disable by suffixing scope with
  `-broken`, for example `scope: [mr-github]` -> `scope: [mr-github-broken]`.
- Unit-test skips use pytest markers instead: `@pytest.mark.flaky_in_dev` skips
  in the default dev environment, and `@pytest.mark.flaky` skips in LTS.
- Do not delete the test case or recipe entry when the goal is discoverability
  and easy re-enable.

---

## Test Layout

```text
tests/
├── unit_tests/          # pytest, 1 node × 8 GPUs, torch.distributed runner
├── functional_tests/    # end-to-end shell + training scripts
│   └── test_cases/
│       └── {model}/{test_case}/
│           ├── model_config.yaml          # training args
│           └── golden_values_{env}_{platform}.json
└── test_utils/
    ├── recipes/
    │   ├── h100/        # YAML recipes for H100 jobs
    │   └── gb200/       # YAML recipes for GB200 jobs
    └── python_scripts/  # helpers (recipe_parser, golden-value download, …)
```

---

## How Tests Execute

The GitHub Actions runner invokes `launch_nemo_run_workload.py`, which uses
**nemo-run** to launch a `DockerExecutor` container. The repo is bind-mounted
at `/opt/megatron-lm`; training data is mounted at `/mnt/artifacts`.

**Unit tests** are dispatched through `torch.distributed.run`:

- Ranks 0 and 3 are tee-d to stdout; all other ranks write only to log files.
- Per-rank log files land at `{assets_dir}/logs/1/` and are uploaded as a
  GitHub artifact after the run.

**Functional tests** are driven by
`tests/functional_tests/shell_test_utils/run_ci_test.sh`. Only rank 0 runs the
pytest validation step; training output from all ranks is uploaded as an artifact.

**Flaky-failure auto-retry**: `launch_nemo_run_workload.py` retries up to
**3 times** for known transient patterns (NCCL timeout, ECC error, segfault,
HuggingFace connectivity, …) before declaring a genuine failure.

---

## Recipe YAML Structure

Recipes live in `tests/test_utils/recipes/` and are parsed by
`tests/test_utils/python_scripts/recipe_parser.py`. Each file expands a
cartesian `products` block into individual workload specs:

```yaml
type: basic
format_version: 1
maintainers: [mcore]
loggers: [stdout]
spec:
  name: "{test_case}_{environment}_{platforms}"
  model: gpt              # maps to tests/functional_tests/test_cases/{model}/
  build: mcore-pyt-{environment}
  nodes: 1
  gpus: 8
  n_repeat: 5
  platforms: dgx_h100
  time_limit: 1800
  script_setup: |
    ...
  script: |-
    bash tests/functional_tests/shell_test_utils/run_ci_test.sh ...
products:
  - test_case: [my_test]
    products:
      - environment: [dev, lts]
        scope: [mr-github]
        platforms: [dgx_h100]
```

Key runtime placeholders: `{assets_dir}`, `{artifacts_dir}`, `{test_case}`,
`{environment}`, `{platforms}`, `{n_repeat}`.

### Disabling a Test Without Deleting It

To temporarily disable a test case in a recipe YAML, suffix its `scope` value
with `-broken` — **do not delete the entry**:

```yaml
# before (test runs in CI)
scope: [mr-github]

# after (test is skipped; entry preserved for easy re-enable)
scope: [mr-github-broken]
```

---

## Running Unit Tests Locally

All unit tests initialize a `torch.distributed` group, so every invocation
requires GPU access and must go through `torch.distributed.run`:

```bash
# Full suite
uv run python -m torch.distributed.run --nproc-per-node 8 -m pytest -q \
  tests/unit_tests

# Single file
uv run python -m torch.distributed.run --nproc-per-node 8 -m pytest -q \
  tests/unit_tests/models/test_gpt_model.py

# Single test
uv run python -m torch.distributed.run --nproc-per-node 8 -m pytest -q \
  tests/unit_tests/models/test_gpt_model.py::TestGPTModel::test_constructor

# Filter by name substring
uv run python -m torch.distributed.run --nproc-per-node 8 -m pytest -q \
  tests/unit_tests -k optimizer
```

### Marker filters

```bash
# Exclude flaky tests during development
uv run python -m torch.distributed.run --nproc-per-node 8 -m pytest -q \
  tests/unit_tests -m "not flaky and not flaky_in_dev"

# Include experimental tests
uv run python -m torch.distributed.run --nproc-per-node 8 -m pytest -q \
  tests/unit_tests --experimental
```

### CI parity

Use `tests/unit_tests/run_ci_test.sh` to reproduce a CI bucket failure exactly.
For ad-hoc runs, prefer the direct `torch.distributed.run` invocations above.

### Gotchas

- `pyproject.toml` sets `addopts = --durations=15 -s -rA` — stdout is not
  captured (`-s`), so ranks interleave during multi-rank runs. Override with
  `--capture=fd` when debugging a specific rank.
- `tests/unit_tests/conftest.py` looks for test data under `/opt/data` and
  attempts a download if missing. Supply it manually or skip data-dependent
  tests when running outside the canonical container.

---

## Adding a Unit Test

1. Create `tests/unit_tests/<category>/test_<name>.py`.
2. Use fixtures from `tests/unit_tests/conftest.py`.
3. Apply markers as needed:
   - `@pytest.mark.internal` — skipped on `legacy` tag
   - `@pytest.mark.flaky_in_dev` — skipped in `dev` environment (CI default; use this to disable a flaky test without blocking the standard pipeline)
   - `@pytest.mark.flaky` — skipped in `lts` environment
   - `@pytest.mark.experimental` — `latest` tag only
4. Verify locally (see Running Unit Tests Locally above).
5. If the test needs a dedicated CI bucket, add an entry to
   `tests/test_utils/recipes/h100/unit-tests.yaml`.

---

## Adding a Functional / Integration Test

1. Create `tests/functional_tests/test_cases/<model>/<test_name>/`.
2. Write `model_config.yaml` with `MODEL_ARGS`, `ENV_VARS`, and `TEST_TYPE`.
3. Add a YAML recipe under `tests/test_utils/recipes/h100/` (and `gb200/` if
   needed). Required fields: `scope`, `environment`, `platform`, `n_repeat`,
   `time_limit`.
4. Push the PR, add the label **"Run functional tests"** to trigger a full run.
5. After a successful run, download golden values:

   ```bash
   python tests/test_utils/python_scripts/download_golden_values.py \
     --source github --pipeline-id <run-id>
   ```

6. Commit the downloaded golden values.

---

## Common Pitfalls

| Problem | Cause | Fix |
|---------|-------|-----|
| Test passes locally but fails in CI | Different environment or data path | Check `DATA_PATH`, `DATA_CACHE_PATH`, and the `environment` tag (`dev` vs `lts`) |
| Golden value mismatch after a code change | Numerical regression | Download new golden values via `download_golden_values.py` after a clean run |
| `cicd-integration-tests-gb200` not triggered | GB200 jobs require maintainer status | Ask a maintainer to trigger, or add the `Run functional tests` label |

© Philip Petrakian · Apache-2.0 · NVIDIA/skills

Similar skills

All skills for Testing and QA →

From the same set195

holoscan-install-container Checks a host and installs the Holoscan SDK 5.x CUDA 13 development container. Use it before running the SDK in Docker with GPU access. CX Codex +1 1,800installs holoscan-setup Checks a Linux host and picks a Holoscan SDK 5.x install path: container, Debian packages, wheels or a source build. CX Codex +1 1,800installs tilegym-adding-cutile-kernel Guides AI coding agents through adding cuTile GPU kernel operators to TileGym. Useful when implementing custom kernels, tests, and benchmarks. CX Codex +1 1,800installs mcore-split-pr This skill maps a pull request’s files to CODEOWNERS groups and proposes smaller PRs with fewer reviewer groups. Use it when a large change brings in too many reviewers. CX Codex +1 1,800installs mcore-create-issue Investigates failing GitHub Actions runs for NVIDIA/Megatron-LM, extracts the error cause, and files a structured bug report. CX Codex +1 1,800installs mcore-run-on-slurm Prepare a SLURM launch for distributed Megatron-LM training, from an sbatch skeleton to rank-level failure checks. Useful when configuring or debugging a multi-node job. CX Codex +1 1,800installs nemo-rl-brev-etiquette A skill that tells the agent where files belong on a Brev box: code stays in the repo, heavy run output goes to /ephemeral. CX Codex +1 1,800installs mcore-linting-and-formatting Sets up linting and code formatting for Megatron-LM projects. It helps fix ruff and mypy violations and sort imports before opening a pull request. CX Codex +1 1,800installs

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor