File size: 640 Bytes
b7751e5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | """Load this repository's custom PyTorch causal language model."""
import json
from pathlib import Path
import torch
from model import CausalLM
from moe import TransformerConfig
def load_model(directory, device="cpu"):
"""Load verified tensor weights and return a model in evaluation mode."""
directory = Path(directory)
config = TransformerConfig(**json.loads((directory / "config.json").read_text()))
model = CausalLM(config)
weights = torch.load(
directory / "model_state.pt", map_location="cpu", weights_only=True
)
model.load_state_dict(weights, strict=True)
return model.eval().to(device)
|