Repository navigation
Conversation
Signed-off-by: Suguna Velury <[email protected]>
There was a problem hiding this comment.
Pull Request Overview
This PR improves the HF checkpoint loading logic by introducing methods to better determine which checkpoint file to use, prioritizing safetensors over bin files.
- Introduced _get_ignore_patterns to dynamically generate file ignore patterns based on repository contents.
- Added _get_checkpoint_file to select the most relevant checkpoint file from a given directory.
- Updated prefetch_checkpoint to leverage the new methods for improved checkpoint handling.
Comments suppressed due to low confidence (1)
tensorrt_llm/_torch/auto_deploy/models/hf.py:223
- Ensure that you add unit tests covering various scenarios for checkpoint selection logic in _get_checkpoint_file to safeguard against regression.
def _get_checkpoint_file(self, checkpoint: Union[str, os.PathLike]) -> Union[str, os.PathLike]:
Signed-off-by: Suguna Velury <[email protected]>
Signed-off-by: Suguna Velury <[email protected]>
Signed-off-by: Lucas Liebenwein <[email protected]>
Signed-off-by: Lucas Liebenwein <[email protected]>
e52eb11 to
b9b2cfd
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR enhances checkpoint loading by prioritizing safetensors over bin files, adds logic to limit memory allocation for sharded models, and replaces the old load_state_dict_with_assign approach with load_checkpoint_in_model.
- Prioritize safetensors in HF repo downloads and correctly select the checkpoint file.
- Remove the deprecated
load_state_dict_with_assignand switch toload_checkpoint_in_model. - Update model factory to randomly initialize parameters on-device before loading weights to prevent OOM.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/unittest/_torch/auto_deploy/unit/singlegpu/models/test_hf.py | Removed tests for the now-removed load_state_dict_with_assign util. |
| tensorrt_llm/_torch/auto_deploy/models/hf.py | Added _get_ignore_patterns, _get_checkpoint_file, and updated loading logic to use load_checkpoint_in_model. |
| tensorrt_llm/_torch/auto_deploy/models/factory.py | Replaced meta-to-empty init with random init (_to_maybe_random) and streamlined the checkpoint loading flow. |
Comments suppressed due to low confidence (2)
tensorrt_llm/_torch/auto_deploy/models/hf.py:276
- After downloading the checkpoint directory, store it in
self._prefetched_path(e.g.,self._prefetched_path = fetched_dir) so subsequent calls reference the correct path and avoid re-downloading.
fetched_dir = snapshot_download(self.model, ignore_patterns=ignore_patterns)
tensorrt_llm/_torch/auto_deploy/models/hf.py:177
- Add unit tests for
_get_ignore_patternsand_get_checkpoint_fileto verify correct filtering of weight files and error handling when no valid checkpoint is found.
def _get_ignore_patterns(self, repo_id: str):
| # if we have safetensors we can ignore all bin files | ||
| if list(filter_repo_objects(items=files, allow_patterns=[safetensors_pattern])): | ||
| ignore_patterns.append(bin_pattern) | ||
| except: # noqa: E722 |
There was a problem hiding this comment.
Avoid a bare except:; catch specific exceptions (e.g., except HFValidationError:) to prevent masking unexpected errors.
| except: # noqa: E722 | |
| except (HFValidationError, ValueError): |
Includes #17 , #18, #21 , #23 * move Phi PR for sprint Signed-off-by: Ubuntu <[email protected]> * remove Phi3 patch and unfuse_weight transformation Signed-off-by: Ubuntu <[email protected]> * update Phi3/4 patches Signed-off-by: Ubuntu <[email protected]> * minor Signed-off-by: Ubuntu <[email protected]> * minor Signed-off-by: Ubuntu <[email protected]> * Update the position id to int64 Signed-off-by: Chenghao Zhang <[email protected]> * Add support for handling aliased parameters Signed-off-by: Suyog Gupta <[email protected]> * update tests Signed-off-by: Suyog Gupta <[email protected]> * lint Signed-off-by: Suyog Gupta <[email protected]> * lint Signed-off-by: Suyog Gupta <[email protected]> * removed load state dict with assign context manager Signed-off-by: Suguna Velury <[email protected]> * formatting fix Signed-off-by: Suguna Velury <[email protected]> * Removed related unit tests Signed-off-by: Suguna Velury <[email protected]> * [AutoDeploy] correctly identifying how to load HF checkpoint weights Signed-off-by: Lucas Liebenwein <[email protected]> * [AutoDeploy] correctly load sharded weights Signed-off-by: Lucas Liebenwein <[email protected]> * skip sharding if num_users>1 Signed-off-by: Suyog Gupta <[email protected]> --------- Signed-off-by: Ubuntu <[email protected]> Signed-off-by: Chenghao Zhang <[email protected]> Signed-off-by: Suyog Gupta <[email protected]> Signed-off-by: Suguna Velury <[email protected]> Signed-off-by: Lucas Liebenwein <[email protected]> Co-authored-by: Ubuntu <[email protected]> Co-authored-by: Chenghao Zhang <[email protected]> Co-authored-by: Suguna Velury <[email protected]> Co-authored-by: Lucas Liebenwein <[email protected]>
|
merged in #25 |
Includes #17 , #18, #21 , #23 * move Phi PR for sprint Signed-off-by: Ubuntu <[email protected]> * remove Phi3 patch and unfuse_weight transformation Signed-off-by: Ubuntu <[email protected]> * update Phi3/4 patches Signed-off-by: Ubuntu <[email protected]> * minor Signed-off-by: Ubuntu <[email protected]> * minor Signed-off-by: Ubuntu <[email protected]> * Update the position id to int64 Signed-off-by: Chenghao Zhang <[email protected]> * Add support for handling aliased parameters Signed-off-by: Suyog Gupta <[email protected]> * update tests Signed-off-by: Suyog Gupta <[email protected]> * lint Signed-off-by: Suyog Gupta <[email protected]> * lint Signed-off-by: Suyog Gupta <[email protected]> * removed load state dict with assign context manager Signed-off-by: Suguna Velury <[email protected]> * formatting fix Signed-off-by: Suguna Velury <[email protected]> * Removed related unit tests Signed-off-by: Suguna Velury <[email protected]> * [AutoDeploy] correctly identifying how to load HF checkpoint weights Signed-off-by: Lucas Liebenwein <[email protected]> * [AutoDeploy] correctly load sharded weights Signed-off-by: Lucas Liebenwein <[email protected]> * skip sharding if num_users>1 Signed-off-by: Suyog Gupta <[email protected]> --------- Signed-off-by: Ubuntu <[email protected]> Signed-off-by: Chenghao Zhang <[email protected]> Signed-off-by: Suyog Gupta <[email protected]> Signed-off-by: Suguna Velury <[email protected]> Signed-off-by: Lucas Liebenwein <[email protected]> Co-authored-by: Ubuntu <[email protected]> Co-authored-by: Chenghao Zhang <[email protected]> Co-authored-by: Suguna Velury <[email protected]> Co-authored-by: Lucas Liebenwein <[email protected]> Signed-off-by: Lucas Liebenwein <[email protected]>
Our current load logic (recommended meta device/hf accelerate approach) requires us to correctly identify which type of checkpoint we want to load from a HF checkpoint directory (safetsensors or bin). It won't choose for us. --> This will correctly filter for the approach prioritizing safetsensors over bin
In addition this PR will also ensure that we don't allocate too much memory during checkpoint loading for sharded models. The added comments in the PR give more details about that.
It also includes Removed load_state_dict() with assign=True #22