[Model Runner V2] batch-sharded sample (#50465)

Signed-off-by: Giancarlo Delfin <gdelfin@inferact.ai>
This commit is contained in:
Giancarlo Delfin
2026-08-24 15:49:57 -07:00
committed by GitHub
parent 0d7d5ed0b2
commit d154d90d6c
19 changed files with 1781 additions and 22 deletions
+11 -4
View File
@@ -63,6 +63,7 @@ class InklingLogitsProcessor(LogitsProcessor):
lm_head: VocabParallelEmbedding,
hidden_states: torch.Tensor,
embedding_bias: torch.Tensor | None = None,
skip_gather: bool = False,
) -> torch.Tensor | None:
# ``base_layer`` exists only on the LogitsProcessorWithLoRA wrapper,
# which calls this forward with ``self`` bound to the wrapper. The
@@ -72,15 +73,16 @@ class InklingLogitsProcessor(LogitsProcessor):
# lives on this class).
if hasattr(self, "base_layer"):
return type(self.base_layer)._lora_forward(
self, lm_head, hidden_states, embedding_bias
self, lm_head, hidden_states, embedding_bias, skip_gather
)
return self._base_forward(lm_head, hidden_states, embedding_bias)
return self._base_forward(lm_head, hidden_states, embedding_bias, skip_gather)
def _lora_forward(
self,
lm_head: VocabParallelEmbedding,
hidden_states: torch.Tensor,
embedding_bias: torch.Tensor | None = None,
skip_gather: bool = False,
) -> torch.Tensor | None:
# ``self`` is the LogitsProcessorWithLoRA wrapper here: ``_get_logits``
# returns the base logits plus the lm_head LoRA delta. Apply the muP
@@ -90,7 +92,9 @@ class InklingLogitsProcessor(LogitsProcessor):
if self.logits_as_input:
logits = hidden_states
else:
logits = self._get_logits(hidden_states, lm_head, embedding_bias)
logits = self._get_logits(
hidden_states, lm_head, embedding_bias, skip_gather
)
# TODO: fuse this multiplication
if logits is not None and mup:
assert self.base_layer.soft_cap is None
@@ -103,10 +107,11 @@ class InklingLogitsProcessor(LogitsProcessor):
lm_head: VocabParallelEmbedding,
hidden_states: torch.Tensor,
embedding_bias: torch.Tensor | None = None,
skip_gather: bool = False,
) -> torch.Tensor | None:
mup = self.logits_mup_width_multiplier
if not mup:
return super().forward(lm_head, hidden_states, embedding_bias)
return super().forward(lm_head, hidden_states, embedding_bias, skip_gather)
# Fold the muP width divisor into the lm_head GEMM alpha (fp32 epilogue):
# no separate elementwise kernel, no bf16 rounding of scaled logits, and
# no weight mutation. Overfit to the served checkpoint: bf16 lm_head, no
@@ -123,6 +128,8 @@ class InklingLogitsProcessor(LogitsProcessor):
beta=0.0,
alpha=1.0 / mup,
)
if skip_gather:
return logits
logits = self._gather_logits(logits)
if logits is not None:
logits = logits[..., : self.org_vocab_size]