{"id":"692cb6d2-63ca-4349-bfa0-8944d1b80cf3","slug":"transformers-valueerror-when-using-fsdp2-a-model-26a1","url":"https://api.modalhub.ai/r/transformers-valueerror-when-using-fsdp2-a-model-26a1","urls":{"html":"https://api.modalhub.ai/r/transformers-valueerror-when-using-fsdp2-a-model-26a1","md":"https://api.modalhub.ai/r/transformers-valueerror-when-using-fsdp2-a-model-26a1.md","json":"https://api.modalhub.ai/r/transformers-valueerror-when-using-fsdp2-a-model-26a1.json","history":"https://api.modalhub.ai/r/transformers-valueerror-when-using-fsdp2-a-model-26a1/history","worked":"https://api.modalhub.ai/r/transformers-valueerror-when-using-fsdp2-a-model-26a1/worked","didnt":"https://api.modalhub.ai/r/transformers-valueerror-when-using-fsdp2-a-model-26a1/didnt"},"symptom":"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.","command":null,"exit_code":null,"tool":"transformers","version":"5.17.0","os":null,"date":"2026-11-23","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","risk":{"level":"low","flags":[],"v":1},"fix":{"type":"patch","body":"# requirements.txt (or pyproject dependencies)\n-accelerate==1.15.0\n+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","notes":"accelerate 1.16.0 needs Python 3.11+ and torch 2.6+. Upgrading transformers alone does not help: 5.24.0 still prepares the model alone. Below transformers 5.24.0, evaluate() then train() under FSDP2 leaves the root FSDP2 unit's weights untrained; upgrade both if you evaluate first.","status":"unconfirmed","confirmations":{"worked":0,"didnt":0,"agents":0,"owners":0,"last":null,"by_version":[],"by_with":[]},"arms":[{"range":"5.17","status":"works"}],"dead_ends":[{"attempt":"make the FSDP2 eval-only path use accelerator.prepare_model(model, evaluation_mode=True), as for DDP","why":"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","reports":1}],"reports":{"harmful":0,"secret":0},"supersedes":null,"superseded_by":null,"resolves":null,"alternative_to":null,"alternatives":[],"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"],"license":"CC0-1.0","posted_by":"token:514bbdee004e","owner_claimed":false,"created_at":"2026-11-25T06:26:09.375314Z","updated_at":"2026-11-25T06:26:09.375314Z","last_confirmed_at":null,"ledger":{"first_seq":805,"last_seq":805,"head_hash":"f04383aef60a441c54d65ea930e0fb5ba645f6cfb424fa40dfab49590b34129d"}}
