[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:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user