-
Notifications
You must be signed in to change notification settings - Fork 26.3k
[jit] Let script module buffer attributes can also cast device/type #19700
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Take a look at test/cpp/api/jit.cpp, pretty sure you can create a scriptmodule in cpp |
@eellison I was looking at this file, it can let you create a ScripModule from the function text using |
|
In cpp you can define a script module with text, save it, and load it. Not sure i'm understanding how this doesn't cover your use case. |
eellison
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! thanks for adding the test.
test/cpp/api/jit.cpp
Outdated
|
|
||
|
|
||
| TEST(TorchScriptTest, Conversion_MultiCUDA) { | ||
| auto module = torch::jit::load("bn_gpu.pt"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add a run of it with GPU tensors first ?
test/cpp/api/jit.cpp
Outdated
| } | ||
|
|
||
|
|
||
| TEST(TorchScriptTest, Conversion_MultiCUDA) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test should be in cpp/jit/, not api/jit.cpp, see testModuleDefine to see an example of a manually added parameter (attributes have pretty much the same API on modules)
torch/csrc/jit/script/module.cpp
Outdated
| for (auto& parameter : get_attributes()) { | ||
| if (parameter.type()->isSubtypeOf(TensorType::get())) { | ||
| // Need to access the `at::Tensor` as a `Variable` here. | ||
| autograd::Variable variable = parameter.value().toTensor(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be moved out to a function so it's not just a copy-paste of the above code for parameters
driazati
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should be committing binaries to the repo to be used in tests
facebook-github-bot
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wanchaol has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
…h#19700) Summary: Tested locally this fix pytorch#19039, did not add a test since there's no way to create a script module in the cpp world. Pull Request resolved: pytorch#19700 Differential Revision: D15094195 Pulled By: wanchaol fbshipit-source-id: fcc2c1e5efbc160d976ae485ba2457442f62f065
this fix #19039