Skip to content

Commit beb4824

Browse files
committed
Document init memory thresholds and CPU fallback
Expand inline comments to explain the memory cost of init-before-parallelize (~4 bytes/param in fp32) and the OOM thresholds (~10B on 40GB, ~20B on 80GB). Point users to --training.enable_cpu_offload as a fallback for larger models.
1 parent 365ef8b commit beb4824

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

flame/train.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,10 +264,14 @@ def main(job_config: JobConfig):
264264
# We need to iterate through model_parts to apply SPMD parallelisms, compilation,
265265
# optimizer, and checkpointing
266266
for m in model_parts:
267-
# Initialize weights before parallelization so that models with
268-
# custom .data= init (e.g. RWKV-7) operate on plain tensors
269-
# instead of DTensors. The temporary full-size allocation is
270-
# freed once FSDP shards the parameters.
267+
# Materialize and initialize weights before applying parallelisms.
268+
# Some models (e.g. RWKV-7) compute position-dependent init values
269+
# as regular tensors and assign via .data, which is incompatible
270+
# with DTensors created by FSDP. Cost: full model in fp32
271+
# temporarily on each rank (~4 bytes/param). This fits comfortably
272+
# for models up to ~10B on 40GB GPUs or ~20B on 80GB GPUs. For
273+
# larger models, set init_device="cpu" (e.g. via
274+
# --training.enable_cpu_offload).
271275
m.to_empty(device=init_device)
272276
with torch.no_grad():
273277
m.post_init()
@@ -278,7 +282,8 @@ def main(job_config: JobConfig):
278282
# confirm that user will be able to view loss metrics on the console
279283
ensure_pp_loss_visible(parallel_dims, job_config, color)
280284
else:
281-
# Initialize weights before parallelization (see PP path above).
285+
# Materialize and initialize weights before parallelization
286+
# (see PP path comment above for rationale and memory thresholds).
282287
model.to_empty(device=init_device)
283288
with torch.no_grad():
284289
model.post_init()

0 commit comments

Comments
 (0)