-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdeploy.py
More file actions
33 lines (25 loc) · 1.02 KB
/
deploy.py
File metadata and controls
33 lines (25 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from argparse import ArgumentParser
from pathlib import Path
from hydra import initialize, compose
from hydra.utils import instantiate
import torch
if __name__ == "__main__":
parser = ArgumentParser()
parser.add_argument("ckpt_dir", type=Path)
args = parser.parse_args()
# get config
with initialize(config_path=str(args.ckpt_dir), version_base=None):
config = compose(config_name="config") # can add overrides here
# device and precision
device, dtype = torch.device("cuda"), torch.float32
torch.set_float32_matmul_precision("high")
# get network
# no need to trace because params already init
network = instantiate(config.network)
network.load_state_dict(torch.load(args.ckpt_dir / "state_dict.pt", weights_only=True))
network.eval()
network.to(device, dtype=dtype)
# always compile network
# reduce-overhead is much faster than default
compiled_network = torch.compile(network, fullgraph=True, mode="reduce-overhead")
print("Now test on some data!")