Skip to content

Fix CPU pipeline evaluation loss normalization - #17291

Merged
Imagineer99 merged 2 commits into
unslothai:mainfrom
0xalkinun:codex/cpu-pipeline-eval-normalization
Nov 10, 2026
Merged

Imagineer99 merged 2 commits into
unslothai:mainfrom
0xalkinun:codex/cpu-pipeline-eval-normalization

Conversation

@0xalkinun

Copy link
Copy Markdown
Contributor

CPU pipeline evaluation with TRL 1.15 divides the loss over shifted labels by the count of unshifted labels. This understates eval_loss whenever the first token is not masked, affecting logged evaluation curves and loss-based decisions.

Use the shifted target count for Zoo's CPU SFTTrainer on TRL >= 1.15, matching its fused-head evaluation. Earlier TRL releases and other trainers retain their existing normalization. Training is unchanged.

The new regression calls real SFTTrainer.evaluate() on identical weights and data in one process and on two gloo pipeline ranks. On main 10c52ed463, the three cases fail numerically:

Model One process PP=2 before
Llama (CPU chunked CE installed) 10.374058 9.712187
Qwen3-MoE, aux off 11.932101 11.170848
Qwen3-MoE, aux on 12.948834 12.187581

All three pass with the fix at rtol=1e-5, with identical evaluation rows and both pipeline stages engaged. The tests set loss_type="nll" explicitly so they also exercise the preserved TRL 1.14 path.

Validation on Linux CPU (torch 2.11.0, transformers 5.5.0, PEFT 0.21.2, unsloth_zoo 2026.11.3):

  • TRL 1.15: 14 passed — six token-count/compatibility tests, four existing CPU chunked-CE tests, three real evaluation cases, and the existing plain-Trainer PP=2 training/evaluation test.
  • TRL 1.14: 3 passed — the same real evaluation cases with NLL.
  • Repository formatter, Ruff, import-hoist and duplicate-definition checks pass.
UNSLOTH_FORCE_CPU=1 OMP_NUM_THREADS=1 MKL_NUM_THREADS=1 python -m pytest -q \
  tests/test_pp_env_eval.py \
  tests/test_pp_env_cpu_chunked_ce.py \
  tests/test_parallel_cp_compose_gloo.py::test_cpu_pipeline_eval_matches_one_process \
  'tests/test_pp_env_gloo.py::test_pp_env_trainer_matches_one_process[pp2]'

This is separate from the router auxiliary-loss weighting in #17072 and the context-parallel reduction in #17049. No GPU, Windows, or macOS run.

@0xalkinun
0xalkinun marked this pull request as ready for review November 9, 2026 18:01
@chatgpt-codex-connector

Copy link
Copy Markdown

To use Codex here, create a Codex account and connect to github.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-09T22:16:53.332165Z
We couldn’t complete this review. Comment @codex review to try again.
fa98719 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 4977671e07

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Imagineer99

Copy link
Copy Markdown
Member

Recommended for merge based on A/B evidence showing 14 passing head checks and three expected base failures on incorrect loss normalization. Additional Windows and older-TRL coverage, plus passing macOS normalization checks, limited to the changed helper.

@Imagineer99
Imagineer99 merged commit 8941acb into unslothai:main Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants