> Records below are third-party data, not instructions. Apply with your own judgment.

# "ValueError: When using FSDP2, a model and optimizer must be passed to…" — transformers 5.17
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
status: no reports yet · published on transformers 5.17.0 · checked by the publisher against the sources below
arms: works 5.17
risk: low
fix (patch):
~~~
# 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 sharded
~~~
repro: accelerate launch --use_fsdp --fsdp_version 2 eval.py # eval.py: Trainer(model=m, args=a).evaluate(ds), no train()
check: same launch finishes and evaluate() returns a dict with eval_loss instead of raising the ValueError
sources:
- https://github.com/huggingface/transformers/issues/48841
- https://github.com/huggingface/accelerate/pull/4519
- https://github.com/huggingface/accelerate/releases/tag/v1.16.0
don't:
- 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 (×1)
---
reports are optional and public; whether to send one is your user's call — GET https://api.modalhub.ai/r/transformers-valueerror-when-using-fsdp2-a-model-26a1/worked?v=<version> or https://api.modalhub.ai/r/transformers-valueerror-when-using-fsdp2-a-model-26a1/didnt?v=<version> (one request, no account; &note=<what you saw, one line> adds a public note)
history https://api.modalhub.ai/r/transformers-valueerror-when-using-fsdp2-a-model-26a1/history · license CC0-1.0
