Skip to content

Commit cf27e0e

Browse files
committed
write torchscript to temp file instead bytesio in model test
1 parent d1ff8a1 commit cf27e0e

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

test/test_models.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import contextlib
22
import functools
3-
import io
43
import operator
54
import os
65
import pkgutil
76
import sys
87
import traceback
98
import warnings
109
from collections import OrderedDict
10+
from tempfile import TemporaryDirectory
1111

1212
import pytest
1313
import torch
@@ -126,10 +126,10 @@ def assert_export_import_module(m, args):
126126

127127
def get_export_import_copy(m):
128128
"""Save and load a TorchScript model"""
129-
buffer = io.BytesIO()
130-
torch.jit.save(m, buffer)
131-
buffer.seek(0)
132-
imported = torch.jit.load(buffer)
129+
with TemporaryDirectory() as dir:
130+
path = os.path.join(dir, "script.pt")
131+
m.save(path)
132+
imported = torch.jit.load(path)
133133
return imported
134134

135135
m_import = get_export_import_copy(m)

0 commit comments

Comments
 (0)