Skip to content

Commit 1967270

Browse files
author
Michael Gschwind
committed
add build.utils.py
1 parent 67dde1d commit 1967270

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

build/utils.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import logging
1010
import os
1111
from pathlib import Path
12-
from typing import List
12+
from typing import List, Dict
1313

1414
import torch
1515

@@ -133,10 +133,20 @@ def device_sync(device="cpu"):
133133

134134

135135
#########################################################################
136-
### general utilkity functions ###
136+
### general utility functions ###
137137

138138

139139
# in fbcode, we can intercept certain local paths that
140140
# should be interpreted as part of an XAR package
141141
def canonical_path(path):
142142
return path
143+
144+
145+
#########################################################################
146+
### general utility functions ###
147+
148+
def state_dict_device(d, device = "cpu") -> Dict:
149+
for key, weight in d.items():
150+
d[key] = weight.to(device=device)
151+
152+
return d

0 commit comments

Comments
 (0)