Skip to content
This repository has been archived by the owner on Nov 22, 2022. It is now read-only.

Back out "disable dual writing, save models to Manifold" #1474

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions pytext/exporters/exporter.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved

import tempfile
from typing import Callable, Dict, List, Tuple, Union

import torch
Expand All @@ -13,7 +12,6 @@
from pytext.data import CommonMetadata
from pytext.fields import FieldMeta
from pytext.utils import onnx
from pytext.utils.file_io import PathManager
from pytext.utils.usage import log_class_usage


Expand Down Expand Up @@ -180,17 +178,12 @@ def export_to_caffe2(

print(f"Saving caffe2 model to: {export_path}")

# caffe2/onnx doesn't support internal uri(i.e. manifold)
# workaround: save to a temp file and copy to model_path
# this will be deprecated soon after caffe2 fully deprecated
_, temp_path = tempfile.mkstemp(prefix="pytext")

c2_prepared = onnx.pytorch_to_caffe2(
model,
self.dummy_model_input,
self.input_names,
self.output_names,
temp_path,
export_path,
export_onnx_path,
)
c2_prepared, final_input_names = self.prepend_operators(
Expand All @@ -215,10 +208,9 @@ def export_to_caffe2(
c2_prepared,
final_input_names,
final_out_names,
temp_path,
export_path,
self.get_extra_params(),
)
PathManager.copy_from_local(temp_path, export_path, overwrite=True)
return final_out_names

def export_to_metrics(self, model, metric_channels):
Expand Down
4 changes: 1 addition & 3 deletions pytext/task/new_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from pytext.models.model import BaseModel
from pytext.trainers import TaskTrainer, TrainingState
from pytext.utils import cuda, onnx
from pytext.utils.file_io import PathManager
from pytext.utils.usage import log_class_usage
from torch import jit, sort

Expand Down Expand Up @@ -341,8 +340,7 @@ def torchscript_export(
)
if export_path is not None:
print(f"Saving torchscript model to: {export_path}")
with PathManager.open(export_path, "wb") as f:
torch.jit.save(trace, f)
trace.save(export_path)
return trace


Expand Down
7 changes: 2 additions & 5 deletions pytext/task/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
from pytext.task.new_task import NewTask
from pytext.trainers import EnsembleTrainer, HogwildTrainer, TaskTrainer
from pytext.utils import cuda
from pytext.utils.file_io import PathManager
from torch import jit


Expand Down Expand Up @@ -274,8 +273,7 @@ def torchscript_export(self, model, export_path=None, **kwargs):
)
if export_path is not None:
print(f"Saving torchscript model to: {export_path}")
with PathManager.open(export_path, "wb") as f:
torch.jit.save(trace, f)
trace.save(export_path)
return trace


Expand Down Expand Up @@ -364,5 +362,4 @@ def torchscript_export(self, model, export_path=None, **kwargs):
model.eval()
if hasattr(model, "torchscriptify"):
jit_module = model.torchscriptify()
with PathManager.open(export_path, "wb") as f:
torch.jit.save(jit_module, f)
jit_module.save(export_path)