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

Support inference value2disk #119

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Learnmore666
Copy link

During the inference process, the intermediate tensor is saved to disk. The current work is not automatically enabled during the compilation process, and a threshold can be set to enable it. After testing, there were issues with the API. Therefore, the current save API was selected and a new weight file was added for saving. In order to pass the final data comparison test, the disk file was read from the Python end for data comparison.

@@ -361,6 +365,13 @@ void ModuleInterpreter::invoke(bool express_type) {
case mem_mode_t::PART_TENSOR_IN_MEM:
invoke_part_in_mem(express_type);
break;
case mem_mode_t::ALL_TENSOR_IN_DISK:
Copy link
Collaborator

Choose a reason for hiding this comment

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

line 37-47 can not set mem_mode to ALL_TENSOR_IN_DISK, so this branch cannot be executed?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, there is no corresponding case here. I modified the mem_ mode=mem_ mode_t: : ALL_ TENSOR_ IN_ DISK for testing, perhaps a threshold greater than 16GB is needed to activate the case. I don't know what the threshold is, but I hope you can set it. In the above test, it was passed.

Copy link
Collaborator

@luluman luluman left a comment

Choose a reason for hiding this comment

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

Please format this change with the clang-format. If you use vscode, it is easy to achieve by this plugin clang-format.

fclose(file);
std::remove("./value2disk.npz");
}
invoke_to_disk("./value2disk.npz",express_type);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This hard coding file name "value2disk.npz" could be improved using llvm TempFile or a related strategy.

Copy link
Author

Choose a reason for hiding this comment

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

In the new commit, the llvm TempFile class was used, which seems to be more complex. In order to obtain the file on the Python side, an additional pybind interface was added because the file name was randomly generated.

@@ -82,6 +82,7 @@ class ModuleInterpreter {
std::map<std::string, Value> value_map;
std::map<std::string, std::shared_ptr<InferenceParameter>> inference_map;
std::map<std::string, std::shared_ptr<std::vector<float>>> mem_map;
std::vector<size_t> store_disk_shape;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need this variable?

lib/Support/ModuleInterpreter.cpp Outdated Show resolved Hide resolved
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.

3 participants