Skip to content

[GLM 5.3 Tests] Reproduce trainer batch-size logprob sensitivity - #2192

Open
hershg wants to merge 3 commits into
NovaSky-AI:mainfrom
hershg:tests/trainer-batch-sensitivity
Open

hershg wants to merge 3 commits into
NovaSky-AI:mainfrom
hershg:tests/trainer-batch-sensitivity

Conversation

@hershg

@hershg hershg commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

What this adds

  • A trainer-only control: score one fixed sequence, two identical copies together, then the original again. Save raw token scores and batch/repeat/duplicate differences; no invented pass/fail tolerance.
  • Reusable runner and tests in examples/model_checks; pinned Qwen fixtures there and GLM-5.3 fixtures in examples/tinker/glm5p3. No optimizer, inference, or weight publication—this does not test router-state drift or LoRA delivery.
  • Explicit preflight/zero-adapter checks and Ray cleanup even when report storage fails.

Evidence

Runtime Mean / max: one row vs duplicated batch Duplicate-row diff Repeat diff
Qwen TP1, historical 5.34e-8 / — 0 0
Qwen TP8, historical 0.030262 / — 0 0
GLM TP8/EP8, historical 0.217588 / 3.24219 0 0
GLM TP8/EP8, current combined stack 0.217588 / 3.24219 0 0

The current GLM rerun completed on one B300 with immutable image sha256:4b7d4ae3e41561bd691862bfed20ee87eb135a8e14b0bee6f6fd6d836d88d26a and integrated SkyRL 09d6f7b83d965b6dc79e5524b920b7a83000a9f8. It scored 64 positions: initialization 497.27s, single row 92.53s, duplicated batch 2.38s, repeat 2.08s. The current PR cleanup changes layout, errors, and cleanup—not the fixed fixture, scoring path, or comparison semantics.

This is an unresolved characterization, not a calibrated learning failure: deterministic repeat and duplicate-row agreement rule out random execution noise, while the large one-row/two-row change remains specific to trainer batch shape. No universal acceptance threshold is asserted here.

Validation / reproduction

Current cleanup: 13 pure tests passed, Ruff/Black/gitleaks passed; renamed fixtures are byte-identical. The expanded 24-test native suite cannot collect on the devbox because its local CUDA environment lacks cuDNN; the live B300 rerun above exercises the actual model path.

uv run --isolated --no-project --with pytest python -m pytest --noconftest \
  examples/model_checks/tests/test_batch_sensitivity.py -q

Inside the pinned prebuilt CUDA image:

uv run --active --no-sync --extra tinker --extra megatron \
  python examples/model_checks/run_batch_sensitivity.py \
  --model /models/304b8051cfb2b260b61ce0cbe330e02a98e73639 \
  --backend-config examples/tinker/glm5p3/batch_sensitivity_config.json \
  --fixture examples/tinker/glm5p3/batch_sensitivity_tokens.json \
  --output-dir /artifacts/glm-batch-sensitivity

@hershg
hershg marked this pull request as ready for review September 9, 2026 21:22

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a batch sensitivity diagnostic tool to compare token scores across different batch sizes on a Megatron trainer, including configuration fixtures and tests for Qwen3-8B and GLM-5.3 models. The review feedback focuses on improving robustness and error handling by replacing bare assert statements with explicit exceptions, adding defensive checks for potential None values in tokenizer padding, and handling missing keys in dictionary lookups.

Comment thread examples/model_checks/run_batch_sensitivity.py Outdated
Comment thread examples/model_checks/tests/test_batch_sensitivity_runtime.py Outdated
Comment thread examples/model_checks/run_batch_sensitivity.py Outdated
Comment thread examples/model_checks/run_batch_sensitivity.py Outdated
Comment thread examples/model_checks/run_batch_sensitivity.py
Comment thread examples/model_checks/batch_sensitivity.py
@greptile-apps

greptile-apps Bot commented Sep 9, 2026

Copy link
Copy Markdown

Confidence Score: 5/5

The PR appears safe to merge, with no concrete changed-code defect identified.

The configured duplicate rows remain together in one token-based microbatch, worker output preserves per-sample scores, and the added validations consistently enforce the diagnostic’s stated input and scoring contracts.

Important Files Changed

Filename Overview
examples/model_checks/run_batch_sensitivity.py Implements the isolated Megatron scoring workflow, validates topology and inputs, records all token scores, and writes incremental reports.
examples/model_checks/batch_sensitivity.py Provides finite, aligned token-score comparisons and separates the three diagnostic error categories.
examples/model_checks/tests/test_batch_sensitivity_runtime.py Verifies batch equality, adapter validation, production scoring dispatch, and output-shape rejection.
examples/model_checks/tests/test_batch_sensitivity.py Covers comparison calculations and malformed or nonfinite score handling.
examples/model_checks/fixtures/qwen3_8b_config.json Pins the single-GPU Qwen Megatron topology and batching settings used by the diagnostic.
examples/tinker/glm53/batch_sensitivity_config.json Pins the eight-GPU GLM tensor/expert-parallel topology and model-specific transformer settings.

Sequence Diagram

sequenceDiagram
    participant Runner
    participant Ray as Ray Actor Group
    participant Worker as Megatron Worker
    participant Report
    Runner->>Ray: Score one fixed sequence
    Ray->>Worker: "forward(loss_fn=None)"
    Worker-->>Runner: Single-row token logprobs
    Runner->>Ray: Score two identical copies together
    Ray->>Worker: "forward(loss_fn=None)"
    Worker-->>Runner: Two token-logprob rows
    Runner->>Ray: Score original sequence again
    Ray->>Worker: "forward(loss_fn=None)"
    Worker-->>Runner: Repeat token logprobs
    Runner->>Report: Compare batch-size, duplicate, and repeat errors
Loading

Reviews (1): Last reviewed commit: "test: isolate trainer batch-size logprob..." | Re-trigger Greptile

@hershg hershg changed the title [tests] Reproduce trainer batch-size logprob sensitivity [GLM 5.3 Tests] Reproduce trainer batch-size logprob sensitivity Sep 10, 2026
Signed-off-by: Hersh Godse <hersh@trajectory.ai>
Signed-off-by: Hersh Godse <hersh@trajectory.ai>
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.

1 participant