-
Notifications
You must be signed in to change notification settings - Fork 520
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced model compression functionality, allowing users to compress models directly via the command-line interface. - Added a new command option `"compress"` to trigger model compression. - Enhanced help messages and examples for the `"compress"` command to clarify usage with different backends. - Added a comprehensive JSON configuration file for model compression parameters. - Improved handling of compression parameters within descriptor classes for better organization and efficiency. - **Bug Fixes** - Improved error handling for unsupported file formats during model loading. - **Tests** - Introduced a suite of unit tests to evaluate the functionality of model compression, ensuring accuracy and performance across different configurations. - Enhanced tests for loading model parameters to ensure all required attributes are correctly handled. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Jinzhe Zeng <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Jinzhe Zeng <[email protected]>
- Loading branch information
1 parent
3701566
commit 0c5ab07
Showing
25 changed files
with
1,003 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# SPDX-License-Identifier: LGPL-3.0-or-later | ||
import json | ||
|
||
import torch | ||
|
||
from deepmd.pt.model.model import ( | ||
get_model, | ||
) | ||
|
||
|
||
def enable_compression( | ||
input_file: str, | ||
output: str, | ||
stride: float = 0.01, | ||
extrapolate: int = 5, | ||
check_frequency: int = -1, | ||
): | ||
saved_model = torch.jit.load(input_file, map_location="cpu") | ||
model_def_script = json.loads(saved_model.model_def_script) | ||
model = get_model(model_def_script) | ||
model.load_state_dict(saved_model.state_dict()) | ||
|
||
model.enable_compression( | ||
extrapolate, | ||
stride, | ||
stride * 10, | ||
check_frequency, | ||
) | ||
|
||
model = torch.jit.script(model) | ||
torch.jit.save(model, output) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.