Skip to content

SFT: device-agnostic chunked linear+CE loss and --gradient-checkpointing forwarding - #330

Merged
michaellchung merged 2 commits into
mainfrom
sft-chunked-ce
Nov 3, 2026
Merged

michaellchung merged 2 commits into
mainfrom
sft-chunked-ce

Conversation

@michaellchung

@michaellchung michaellchung commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Add --kernel-backend chunked: a device-agnostic linear+cross-entropy SFT loss. The causal LM runs to its final hidden states and the loss computes hidden @ lm_head.weight^T plus CE over --loss-chunk-tokens target rows at a time under non-reentrant activation checkpointing, so full-sequence [seq, vocab] logits are never materialized in forward or backward.
  • Semantics match the native sft_loss (label shift, assistant mask, fractional token weights, FP32 CE, token-sum reduction, target count). Tied embeddings are supported; soft-capped/scaled heads, LoRA on lm_head, quantized bases and non-DDP sharding are refused.
  • The launcher forwards --loss-chunk-tokens and, when set explicitly, --gradient-checkpointing to torch learners; default learner commands are unchanged.
  • Docs: flag reference rows in docs/A100_KERNELS.md and a long-context section in docs/ASCEND.md.

Tests

  • tests/test_chunked_ce.py: loss and gradient parity with the native loss (masks, fractional weights, tied embeddings), refusal cases.
  • tests/test_island_backend.py: launcher forwarding of the new flags.

🤖 Generated with Claude Code

MichaelChung and others added 2 commits November 3, 2026 12:53
--kernel-backend chunked runs the causal LM to its final hidden states and
computes the cross-entropy over --loss-chunk-tokens rows at a time under
activation checkpointing, so full-sequence logits are never materialized in
forward or backward. Semantics match the native sft_loss. Works on any
device family; the launcher forwards the chunk size to learners.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The flag defaults to auto and is passed only when set explicitly, so default
learner commands are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@michaellchung
michaellchung merged commit a55aa15 into main Nov 3, 2026
3 of 4 checks passed
@michaellchung
michaellchung deleted the sft-chunked-ce branch November 3, 2026 06:24
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