[Bugfix] Stream Llama4 weight loading to avoid host-OOM with copy-returning loaders (#44645)

Signed-off-by: Noa Neria <nneria@nvidia.com>
This commit is contained in:
Noa Neria
2026-06-14 19:23:44 -07:00
committed by GitHub
parent 3d6ce816f0
commit 1801fad0ba
2 changed files with 64 additions and 72 deletions
+6 -2
View File
@@ -798,10 +798,14 @@ class Llama4ForCausalLM(LlamaForCausalLM, MixtureOfExperts):
self,
skip_prefixes=(["lm_head."] if self.config.tie_word_embeddings else None),
)
weights = [
# Use a generator (not a list comprehension) so the weights iterator is
# consumed lazily by AutoWeightsLoader. Materializing it here would hold
# the entire language-model checkpoint in host memory at once, which can
# OOM loaders that return private copies rather than mmap views.
weights = (
self.permute_qk_weight_for_rotary(name, loaded_weight)
for name, loaded_weight in weights
]
)
return loader.load_weights(weights)
def permute_qk_weight_for_rotary(