Skip to content
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

[RUNTIME] Unify load params interface #7559

Merged
merged 13 commits into from
Mar 9, 2021

Conversation

tkonolige
Copy link
Contributor

This allows the VM to load parameters just using the runtime. This way we can run a model in the runtime the same way we can with the graph runtime.

I had to move Map into the runtime, so the diff is large.

@jroesch @areusch

@junrushao
Copy link
Member

Thanks for the contribution Tristan! Would you like to elaborate why we need to move the Map to runtime? If we decide to do it, probably we need a separate PR to make things more reviewable

@tkonolige
Copy link
Contributor Author

LoadParams is a free standing function that we would like to use at runtime with the VM (because there is no clear way to directly load parameters into the VM). It makes the most sense that this function returns a Map from parameter name to NDArray.

@tqchen tqchen assigned tqchen and junrushao and unassigned tqchen Mar 2, 2021
@jroesch
Copy link
Member

jroesch commented Mar 2, 2021

@junrushao1994 I think prematurely optimizing for the runtime library size is a mistake, there are other things like error handling, etc which we want to pull into the runtime which will require Map. My understanding was main push on slim runtime was from FB folks who no longer are actively contributing. We should add it to the runtime unless there is a really compelling reason to not have it.

@junrushao
Copy link
Member

junrushao commented Mar 2, 2021

My understanding is that if we really want a slim runtime, we should go with utvm @areusch

@tqchen
Copy link
Member

tqchen commented Mar 2, 2021

OK, I think perhaps it makes sense to bring Map into runtime given the the goal of slim runtime is covered by uTVM CRT. Let us open another PR for the Map migration though. @junrushao1994 can you do that given you wrote the original map ?

@tkonolige
Copy link
Contributor Author

I left the map migration as a separate commit. I'll cherry-pick and submit

@junrushao
Copy link
Member

@tkonolige Feel free to submit a separate PR and let's merge it in quickly

@jroesch
Copy link
Member

jroesch commented Mar 2, 2021

@junrushao1994 @tqchen thanks! this helps support some refactors I want to do as well.

* \return Map of parameter name to parameter value.
*/
Map<String, NDArray> LoadParams(dmlc::Stream* strm);
// /*!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

intentional?

@@ -79,5 +79,100 @@ TVM_REGISTER_OBJECT_TYPE(ADTObj);
TVM_REGISTER_OBJECT_TYPE(StringObj);
TVM_REGISTER_OBJECT_TYPE(ClosureObj);

TVM_REGISTER_OBJECT_TYPE(ArrayNode);

TVM_REGISTER_GLOBAL("node.Array").set_body([](TVMArgs args, TVMRetValue* ret) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's weird to have the term "node" in the runtime

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed in #7570

@tkonolige tkonolige force-pushed the runtime_params_serialize branch from 002fe4d to 512f088 Compare March 3, 2021 23:48
@tkonolige
Copy link
Contributor Author

@areusch @junrushao1994 Map is now in runtime. Can you re-review?

@tkonolige tkonolige force-pushed the runtime_params_serialize branch from 9cc0087 to 97d194b Compare March 4, 2021 22:27
Map<String, NDArray> params = ::tvm::runtime::LoadParams(strm);
for (auto& p : params) {
uint32_t eid = this->entry_id(input_nodes_[GetInputIndex(p.first)], 0);
data_entry_[eid].CopyFrom(p.second);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possible to do this zero-copy?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not possible. The data has to be loaded onto the cpu and then copied to the device.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok nvm, you're right

Copy link
Contributor

@tmoreau89 tmoreau89 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@junrushao junrushao merged commit 89bafd5 into apache:main Mar 9, 2021
trevor-m pushed a commit to trevor-m/tvm that referenced this pull request May 6, 2021
trevor-m pushed a commit to neo-ai/tvm that referenced this pull request May 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants