Skip to content

tinker seam: re-port onto upstream 2cb59235 (multi-LoRA era) + pin sglang-miles - #3

Merged
GavinZhu-GMI merged 7 commits into
mainfrom
tinker-seam-upstream-2607
Jul 30, 2026
Merged

tinker seam: re-port onto upstream 2cb59235 (multi-LoRA era) + pin sglang-miles#3
GavinZhu-GMI merged 7 commits into
mainfrom
tinker-seam-upstream-2607

Conversation

@GavinZhu-GMI

Copy link
Copy Markdown
Owner

Second seam re-port, same two-phase shape as PR #2: main has been hard-synced to upstream 2cb59235 (130 commits, incl. the multi-LoRA stack radixark#1742-radixark#1748/radixark#1794 and sglang v0.5.16 bump); this PR rebases the 6-commit tinker seam on top and adds one pin commit.

Conflicts resolved in the replay

  • training_utils/loss.py: upstream multi-LoRA and the seam both override global_batch_size for deferred normalization — both retained, seam's _loss_norm_total takes precedence when present (the two paths are disjoint today).
  • megatron_utils/model.py: seam's _build_train_forward_step extraction re-done around upstream's multi-LoRA train_one_step (retain-grads preamble + per-slot stepping preserved verbatim; the shared forward_step body keeps set_tokens_per_adapter_slot).
  • utils/data.py / train_data_conversion.py: _partition_indices follows the partition logic into process_rollout_data_shard; key-list unions.

New commit

  • docker: pin SGLANG_COMMIT to sglang-miles tip 3003d70f6 — FETCH_HEAD builds are unreproducible; the pinned SHA carries sglang#32376/#32421 (multi-LoRA serving fixes), matching the existing Megatron-Bridge SHA-pin convention.

Old main archived at main-archive-20260730 (= df3f75cd, the 20260715 image source).

Merge via rebase-merge to keep main linear (= upstream + seam + pin).

GavinZhu-GMI and others added 7 commits July 30, 2026 06:29
…er step)

Tinker's API pipelines N forward_backward calls then one optim_step; upstream
couples fwd+bwd+step inside train_one_step. This adds the minimal seam
(specs/005 design in tinker-nemorl), reusing upstream data/loss/fanout:

- model.py: extract _build_train_forward_step + _configure_train_step from
  train_one_step/train (pure moves); add forward_backward_pass (no step,
  grads accumulate across calls) and optimizer_step (per-call LR override;
  when the client sets LR the Megatron scheduler is not stepped).
- loss: per-batch _loss_type_override (per-request loss selection) and
  _loss_norm_total (=1 -> pure-sum gradients, invariant to how a batch is
  split across forward_backward calls; fixes the 2x grad inflation measured
  in the G1 spike). Same rollout-key pattern as dynamic_global_batch_size.
- data: forward the two scalar keys in get_batch; keep _partition_indices in
  process_rollout_data so per-sample outputs reassemble into client order.
- actor: forward_backward_only / apply_optimizer_step / forward_logprobs /
  load_checkpoint (full resume incl. optimizer+scheduler).
- ray/tinker_group.py (new): TinkerTrainGroup(RayTrainGroup) async fanout +
  DP-order merge. Frozen v1 RayTrainGroup untouched.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Tinker clients send advantages/log_probs/returns/values per sample (no
actor-side compute_advantages_and_returns), and the seam's scalar keys
(_loss_type_override, _loss_norm_total) must reach every rank. Add them to
split_train_data_by_dp_raw's whitelists; absent keys are skipped, so
non-Tinker paths are unaffected.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Tinker's fb contract includes per-datum logprobs (the SDK weights its
chunk reduction by len(loss_fn_outputs) and the cookbook computes NLL
from them). Computed via a forward-only pass on the same pre-step
weights; extracting them from the loss pass itself is a follow-up
optimization.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Fixes multi-fb grad accumulation on bridge-LoRA (G1 ratio 0.698 ~ 1/sqrt(2)).
Probe evidence: fb2-entry buffer norms exactly equal fb1-exit (nothing
zeroes), but fb2-exit barely moves / can DECREASE (219.23->219.35;
199.85->173.85) instead of matching the fresh fb(8) norms — the per-fb
finalize (reduce-scatter) rewrites local grads with reduced shards, so the
next backward accumulates onto corrupted contents. The raw full-FT path
survived only by ddp_config luck (exact 1.0).

Fix mirrors megatron's own microbatch accumulation: fb passes run with a
no-op finalize_model_grads_func (restored after), and optimizer_step calls
finalize_model_grads once over the locally-accumulated buffers before
optimizer.step().

Runtime-verified 2026-07-14 (ns.config 4xH200, DP=4, Qwen2.5-0.5B
bridge-LoRA): accumulation probe grad_norm bit-identical for 1xfb(8) vs
2xfb(4) + step (ratio exactly 1.0, was 0.698); full G1/G2 gates + sl_basic
recipe rerun green.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Branch-tip (FETCH_HEAD) builds are unreproducible; pin the SHA that
carries the multi-LoRA serving fixes (sglang#32376, #32421), matching
the SHA-pin convention already used for Megatron-Bridge.
@GavinZhu-GMI
GavinZhu-GMI merged commit 16150c2 into main Jul 30, 2026
3 of 5 checks passed
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