[AutoDeploy] Enhance checkpoint loading pipeline
More robust usage of load_checkpoint_in_model
- Investigate load_checkpoint_in_model's load_hook applying issue:
- understand the difference between set_model_state_dict and the torch-native module.load_state_dict, the first one works for the DS FP4 case while the second doesn't
- Add unit tests for our use case(e.g. load_hook) and guard around version updates
Hi, I found and reproduced a current checkpoint-loading correctness issue that is independent of the cross-shard hook problem in #11541. I would like to contribute a fix if this scope fits #5555.
On current main (573bd5f0b8414566bd6183f74b06f8c8a99e6a69), hf_load_state_dict_with_device replaces accelerate.utils.modeling.load_state_dict and its logger level globally. The context manager has no ownership or serialization guard, so overlapping model loads compose wrappers and restore stale global snapshots.
Using the exact current-source context manager and a deterministic two-thread CPU fixture:
device-aenters;device-benters and calls the loader whiledevice-aremains active;- the original loader receives
device-a, notdevice-b; - after
device-aexits, the still-activedevice-bcontext calls again and receives no device map; - after both contexts exit, the original loader is not restored and the logger remains at
ERRORinstead ofINFO.
The same result reproduced in three consecutive repetitions. No CUDA operation is needed because the defect is the global patch ownership/lifetime contract; a GPU test can remain an upstream integration control.
My proposed narrow scope is:
- remove the process-global patch if Accelerate offers a supported per-call route, or otherwise serialize/own it with correct nesting and exception restoration;
- preserve the existing single-context behavior;
- add deterministic overlap, nesting, exception, and logger-restoration regression tests;
- avoid mixing in the safetensor logical-group fix from #11541.
Could a TensorRT-LLM engineer confirm this direction and make the issue available for an external contribution?