Download tools/extract_model.py from TaiYa1/Test: direct link, hf CLI and curl.
- Browser
- Download file 557 Bytes
-
https://huggingface.co/spaces/TaiYa1/Test/resolve/main/tools/extract_model.py
- Command line
-
hf download hf://spaces/TaiYa1/Test/tools/extract_model.py
-
curl -L -o extract_model.py https://huggingface.co/spaces/TaiYa1/Test/resolve/main/tools/extract_model.py
557 Bytes
| import click | |
| import torch | |
| from loguru import logger | |
| def main(model_path, output_path): | |
| if model_path == output_path: | |
| logger.error("Model path and output path are the same") | |
| return | |
| logger.info(f"Loading model from {model_path}") | |
| state_dict = torch.load(model_path, map_location="cpu")["state_dict"] | |
| torch.save(state_dict, output_path) | |
| logger.info(f"Model saved to {output_path}") | |
| if __name__ == "__main__": | |
| main() | |