Skip to content

Commit c2eeb96

Browse files
convert non-cpu const tensor storage to cpu before serialization
1 parent 001927f commit c2eeb96

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

exir/emit/_emitter.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,8 @@ def _tensor_spec_to_evalue(self, spec: TensorSpec) -> EValue:
368368
if spec.const:
369369
# Tensor with a blob we need to serialize. May not actually be constant at runtime
370370
# if it's a weight with an associated gradient
371+
if spec.storage.device.type != "cpu":
372+
spec.storage = spec.storage.cpu()
371373
spec_array_type = (
372374
ctypes.c_char * typing.cast(torch.UntypedStorage, spec.storage).nbytes()
373375
)

0 commit comments

Comments
 (0)