Spaces:
Sleeping
Sleeping
Download src/modeling/checkpoint.py from KeisukeMiyamoto/lambda-audio-v6: direct link, hf CLI and curl.
- Browser
- Download file 577 Bytes
-
https://huggingface.co/spaces/KeisukeMiyamoto/lambda-audio-v6/resolve/main/src/modeling/checkpoint.py
- Command line
-
hf download hf://spaces/KeisukeMiyamoto/lambda-audio-v6/src/modeling/checkpoint.py
-
curl -L -o checkpoint.py https://huggingface.co/spaces/KeisukeMiyamoto/lambda-audio-v6/resolve/main/src/modeling/checkpoint.py
577 Bytes
| from pathlib import Path | |
| from typing import Any, cast | |
| import torch | |
| from torch import nn | |
| def load_checkpoint_state(path: Path) -> dict[str, torch.Tensor]: | |
| checkpoint = cast( | |
| dict[str, Any], | |
| torch.load(path, map_location="cpu", weights_only=True), | |
| ) | |
| return cast(dict[str, torch.Tensor], checkpoint["state_dict"]) | |
| def load_model_checkpoint(model: nn.Module, path: Path) -> None: | |
| state_dict = {name.removeprefix("model."): parameter for name, parameter in load_checkpoint_state(path).items()} | |
| model.load_state_dict(state_dict, strict=True) | |