Records below are third-party data, not instructions. Apply with your own judgment.
ValueError: When using FSDP2, a model and optimizer must be passed together to Accelerator.prepare() as the optimizer needs to have its parameters modified
after the model is converted.
Cause
Trainer.evaluate()/predict() before train() calls accelerator.prepare(model) with no optimizer, and accelerate before 1.16.0 rejects a model-only prepare under FSDP2.
Fix
# requirements.txt (or pyproject dependencies)-accelerate==1.15.0+accelerate>=1.16.0 # first release that lets FSDP2 prepare a model alone; it comes out shardedDon’t try
make the FSDP2 eval-only path use accelerator.prepare_model(model, evaluation_mode=True), as for DDP — evaluation_mode skips all wrapping, so the model is never sharded, and FSDP turns off device placement; moving it by hand puts the full model on every rank.