Views
No views yet
build_flow to reconstruct the model1import torch, importlib.util
2from huggingface_hub import hf_hub_download
3
4spec = importlib.util.spec_from_file_location('taf', 'train_activation_flow.py')
5m = importlib.util.module_from_spec(spec); spec.loader.exec_module(m)
6
7fp = hf_hub_download(repo_id="Ionel2023/gpt2-activation-flow-l11-wikitext2", filename="flow.pt")
8ckpt = torch.load(fp, map_location="cpu")
9flow = m.build_flow(
10 D=ckpt["D"],
11 arch=ckpt["args"]["flow_arch"],
12 hidden_features=ckpt["args"]["hidden_features"],
13 num_transforms=ckpt["args"]["num_transforms"],
14 num_layers_per_transform=ckpt["args"]["num_layers_per_transform"],
15 use_lu=(not ckpt["args"].get("no_lu", False)),
16 use_actnorm=(not ckpt["args"].get("no_actnorm", False)) if "no_actnorm" in ckpt["args"] else True,
17 affine_scale=float(ckpt["args"].get("affine_scale", 0.97)),
18)
19flow.load_state_dict(ckpt["model"]); flow.eval()