Skip to content

Commit c235be4

Browse files
suofacebook-github-bot
authored andcommitted
[jit] kill script namespace (pytorch#34515)
Summary: Pull Request resolved: pytorch#34515 Once upon a time we thought this was necessary. In reality it is not, so removing it. For backcompat, our public interface (defined in `api/`) still has typedefs to the old `script::` names. There was only one collision: `Pass` as a `Stmt` and `Pass` as a graph transform. I renamed one of them. Test Plan: Imported from OSS Differential Revision: D20353503 Pulled By: suo fbshipit-source-id: 48bb911ce75120a8c9e0c6fb65262ef775dfba93
1 parent cf8b728 commit c235be4

File tree

152 files changed

+559
-694
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

152 files changed

+559
-694
lines changed

android/pytorch_android/generate_test_asset.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ int main(int argc, char* argv[]) {
1313
std::ifstream ifs(input_file_path);
1414
std::stringstream buffer;
1515
buffer << ifs.rdbuf();
16-
torch::jit::script::Module m("TestModule");
16+
torch::jit::Module m("TestModule");
1717

1818
m.define(buffer.str());
1919
m.save(output_file_path);

android/pytorch_android/src/main/cpp/pytorch_jni_jit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class MemoryReadAdapter final : public caffe2::serialize::ReadAdapterInterface {
5858
class PytorchJni : public facebook::jni::HybridClass<PytorchJni> {
5959
private:
6060
friend HybridBase;
61-
torch::jit::script::Module module_;
61+
torch::jit::Module module_;
6262

6363
public:
6464
constexpr static auto kJavaDescriptor = "Lorg/pytorch/NativePeer;";

android/pytorch_android/src/main/java/org/pytorch/Module.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import com.facebook.soloader.nativeloader.NativeLoader;
66
import com.facebook.soloader.nativeloader.SystemDelegate;
77

8-
/** Java wrapper for torch::jit::script::Module. */
8+
/** Java wrapper for torch::jit::Module. */
99
public class Module {
1010

1111
private INativePeer mNativePeer;
@@ -14,7 +14,7 @@ public class Module {
1414
* Loads a serialized TorchScript module from the specified path on the disk.
1515
*
1616
* @param modelPath path to file that contains the serialized TorchScript module.
17-
* @return new {@link org.pytorch.Module} object which owns torch::jit::script::Module.
17+
* @return new {@link org.pytorch.Module} object which owns torch::jit::Module.
1818
*/
1919
public static Module load(final String modelPath) {
2020
if (!NativeLoader.isInitialized()) {
@@ -49,7 +49,7 @@ public IValue runMethod(String methodName, IValue... inputs) {
4949
}
5050

5151
/**
52-
* Explicitly destroys the native torch::jit::script::Module. Calling this method is not required,
52+
* Explicitly destroys the native torch::jit::Module. Calling this method is not required,
5353
* as the native object will be destroyed when this object is garbage-collected. However, the
5454
* timing of garbage collection is not guaranteed, so proactively calling {@code destroy} can free
5555
* memory more quickly. See {@link com.facebook.jni.HybridData#resetNative}.

aten/src/ATen/core/function.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ TORCH_API void preoptimizeGraph(std::shared_ptr<Graph>& graph);
2222

2323
// A Function is a pure Graph with no implicit `self` object bound.
2424
// It contains schema information, and the executor that manages the
25-
// execution of the function. script::Method is a wrapper around a
25+
// execution of the function. Method is a wrapper around a
2626
// underlying Function that also provides a `self` object.
2727
struct TORCH_API Function {
2828
virtual bool isGraphFunction() const = 0;

aten/src/ATen/core/ivalue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ std::vector<std::pair<IValue, IValue>> iterationOrder(const c10::Dict<IValue, IV
378378
}
379379

380380
StrongTypePtr::StrongTypePtr(
381-
std::shared_ptr<torch::jit::script::CompilationUnit> cu,
381+
std::shared_ptr<torch::jit::CompilationUnit> cu,
382382
std::shared_ptr<Type> type) {
383383
cu_ = std::move(cu);
384384
type_ = type;

aten/src/ATen/core/ivalue.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ namespace jit {
1111
class CustomClassHolder : public c10::intrusive_ptr_target {};
1212

1313
struct Function;
14-
namespace script {
1514
struct CompilationUnit;
1615
struct Module;
17-
}
1816
} // namespace jit
1917
} // namespace torch
2018
namespace c10 {
@@ -356,7 +354,7 @@ struct CAFFE2_API IValue final {
356354
c10::intrusive_ptr<ivalue::Object> toObject() const & ;
357355
const ivalue::Object& toObjectRef() const;
358356

359-
torch::jit::script::Module toModule() const;
357+
torch::jit::Module toModule() const;
360358
bool isModule() const;
361359

362360
// PyObject
@@ -692,10 +690,10 @@ struct CAFFE2_API WeakIValue final {
692690
// guaranteed to stay alive as long as we hold this object.
693691
struct TORCH_API StrongTypePtr {
694692
StrongTypePtr(
695-
std::shared_ptr<torch::jit::script::CompilationUnit> cu,
693+
std::shared_ptr<torch::jit::CompilationUnit> cu,
696694
std::shared_ptr<Type> type);
697695

698-
std::shared_ptr<torch::jit::script::CompilationUnit> cu_;
696+
std::shared_ptr<torch::jit::CompilationUnit> cu_;
699697
std::shared_ptr<Type> type_;
700698
};
701699

aten/src/ATen/core/ivalue_inl.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
namespace torch {
1616
namespace jit {
1717
struct Function;
18-
namespace script {
1918
struct CompilationUnit;
20-
}
2119
} // namespace jit
2220
} // namespace torch
2321
namespace c10 {
@@ -406,7 +404,7 @@ struct C10_EXPORT ivalue::Object final : c10::intrusive_ptr_target {
406404
}
407405
std::shared_ptr<ClassType> type() const;
408406

409-
std::shared_ptr<torch::jit::script::CompilationUnit> compilation_unit() {
407+
std::shared_ptr<torch::jit::CompilationUnit> compilation_unit() {
410408
return type_.cu_;
411409
}
412410

@@ -868,7 +866,7 @@ IValue from_(c10::intrusive_ptr<T> x, std::false_type) {
868866
auto res = getCustomClassType<inputType>();
869867
auto retObject = ivalue::Object::create(
870868
StrongTypePtr(
871-
std::shared_ptr<torch::jit::script::CompilationUnit>(),
869+
std::shared_ptr<torch::jit::CompilationUnit>(),
872870
std::move(res)),
873871
1);
874872
auto objPtr = c10::static_intrusive_pointer_cast<torch::jit::CustomClassHolder>(std::move(x));

aten/src/ATen/core/jit_type.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717
struct ClassType;
1818
namespace torch {
1919
namespace jit {
20-
namespace script {
2120
struct CompilationUnit;
22-
}
2321
} // namespace jit
2422
} // namespace torch
2523

@@ -1491,7 +1489,7 @@ CAFFE2_API bool elementTypeCanBeInferredFromMembers(const TypePtr& elem_type);
14911489

14921490
struct ClassType;
14931491
using ClassTypePtr = std::shared_ptr<ClassType>;
1494-
using ::torch::jit::script::CompilationUnit;
1492+
using ::torch::jit::CompilationUnit;
14951493

14961494
// This represents a class in TorchScript.
14971495
struct CAFFE2_API ClassType : public NamedType {
@@ -1801,7 +1799,7 @@ struct CAFFE2_API ClassType : public NamedType {
18011799

18021800
struct InterfaceType;
18031801
using InterfaceTypePtr = std::shared_ptr<InterfaceType>;
1804-
using ::torch::jit::script::CompilationUnit;
1802+
using ::torch::jit::CompilationUnit;
18051803

18061804
// Interfaces are a list of abstract methods that a class might meet.
18071805
// If a class provides those methods, it implicitly meets the interface.

binaries/dump_operator_names.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
namespace torch {
2626
namespace jit {
27-
void dump_opnames(const script::Module& m, std::unordered_set<std::string>& opnames) {
27+
void dump_opnames(const Module& m, std::unordered_set<std::string>& opnames) {
2828
auto methods = m.get_methods();
2929
for (const auto& method : methods) {
3030
const auto& func = method.function();

caffe2/contrib/pytorch/script_module_op.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
namespace caffe2 {
88

99
using torch::jit::IValue;
10-
using torch::jit::script::Method;
11-
using torch::jit::script::Module;
10+
using torch::jit::Method;
11+
using torch::jit::Module;
1212

1313
namespace {
1414
class ScriptModuleSerializer : public BlobSerializerBase {
@@ -31,7 +31,7 @@ class ScriptModuleSerializer : public BlobSerializerBase {
3131
// the more efficient serialization version (if we ever get to that point)
3232
BlobProto blob_proto;
3333
blob_proto.set_name(name);
34-
blob_proto.set_type("torch::jit::script::Module");
34+
blob_proto.set_type("torch::jit::Module");
3535
blob_proto.set_content(ss.str());
3636
acceptor(name, SerializeBlobProtoAsString_EnforceCheck(blob_proto));
3737
}
@@ -134,7 +134,7 @@ REGISTER_BLOB_SERIALIZER(
134134
// NB: the first argument to REGISTER_BLOB_DESERIALIZER macro doesn't really
135135
// need to be a real type, it just get converted to string
136136
REGISTER_BLOB_DESERIALIZER(
137-
torch::jit::script::Module,
137+
torch::jit::Module,
138138
ScriptModuleDeserializer);
139139

140140
OPERATOR_SCHEMA(ScriptModule)

caffe2/python/pybind_state.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,12 @@ REGISTER_BLOB_FETCHER((TypeMeta::Id<string>()), StringFetcher);
9494
class ScriptModuleFetcher : public BlobFetcherBase {
9595
public:
9696
pybind11::object Fetch(const Blob& blob) override {
97-
return py::cast(*blob.Get<std::unique_ptr<torch::jit::script::Module>>());
97+
return py::cast(*blob.Get<std::unique_ptr<torch::jit::Module>>());
9898
}
9999
};
100100

101101
REGISTER_BLOB_FETCHER(
102-
(TypeMeta::Id<std::unique_ptr<torch::jit::script::Module>>()),
102+
(TypeMeta::Id<std::unique_ptr<torch::jit::Module>>()),
103103
caffe2::python::ScriptModuleFetcher);
104104
#endif
105105

@@ -247,9 +247,9 @@ bool feedBlob(
247247
return true;
248248
}
249249
#ifdef FBCODE_CAFFE2
250-
if (auto module = torch::jit::script::as_module(arg)) {
251-
blob->GetMutable<std::unique_ptr<torch::jit::script::Module>>()->reset(
252-
new torch::jit::script::Module(*module));
250+
if (auto module = torch::jit::as_module(arg)) {
251+
blob->GetMutable<std::unique_ptr<torch::jit::Module>>()->reset(
252+
new torch::jit::Module(*module));
253253
return true;
254254
}
255255
#endif

docs/source/jit.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ Disable JIT for Debugging
213213
Python. Since TorchScript (scripting and tracing) are disabled with this flag,
214214
you can use tools like ``pdb`` to debug the model code.
215215

216-
Given an example script::
216+
Given an example
217217

218218
@torch.jit.script
219219
def scripted_fn(x : torch.Tensor):

docs/source/notes/large_scale_deployments.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ usage might look like:
120120

121121
.. code-block:: cpp
122122
123-
SetExportModuleExtraFilesHook([](const script::Module&) {
124-
script::ExtraFilesMap files;
123+
SetExportModuleExtraFilesHook([](const Module&) {
124+
ExtraFilesMap files;
125125
files["producer_info.json"] = "{\"user\": \"" + getenv("USER") + "\"}";
126126
return files;
127127
});

docs/source/org/pytorch/Module.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Module
88

99
.. java:type:: public class Module
1010
11-
Java wrapper for torch::jit::script::Module.
11+
Java wrapper for torch::jit::Module.
1212

1313
Methods
1414
-------
@@ -18,7 +18,7 @@ destroy
1818
.. java:method:: public void destroy()
1919
:outertype: Module
2020

21-
Explicitly destroys the native torch::jit::script::Module. Calling this method is not required, as the native object will be destroyed when this object is garbage-collected. However, the timing of garbage collection is not guaranteed, so proactively calling \ ``destroy``\ can free memory more quickly. See \ :java:ref:`com.facebook.jni.HybridData.resetNative`\ .
21+
Explicitly destroys the native torch::jit::Module. Calling this method is not required, as the native object will be destroyed when this object is garbage-collected. However, the timing of garbage collection is not guaranteed, so proactively calling \ ``destroy``\ can free memory more quickly. See \ :java:ref:`com.facebook.jni.HybridData.resetNative`\ .
2222

2323
forward
2424
^^^^^^^
@@ -40,7 +40,7 @@ load
4040
Loads a serialized TorchScript module from the specified path on the disk.
4141

4242
:param modelPath: path to file that contains the serialized TorchScript module.
43-
:return: new \ :java:ref:`org.pytorch.Module`\ object which owns torch::jit::script::Module.
43+
:return: new \ :java:ref:`org.pytorch.Module`\ object which owns torch::jit::Module.
4444

4545
runMethod
4646
^^^^^^^^^

ios/TestApp/TestAppTests/TestAppTests.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ @interface TestAppTests : XCTestCase
77
@end
88

99
@implementation TestAppTests {
10-
torch::jit::script::Module _module;
10+
torch::jit::Module _module;
1111
}
1212

1313
+ (void)setUp {

0 commit comments

Comments
 (0)