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

Share memory in single session without user specification #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

okdshin
Copy link
Member

@okdshin okdshin commented Apr 8, 2023

Description

Removed is_shared_initializer from the decision to cache pre-packed weights. This allows memory to be shared within a single session even if the user does not specify it, thus reducing memory usage.

Motivation and Context

In the current implementation, memory is not shared even if the model shares parameters among multiple layers. There is a mechanism to share memory specified by the user, but the memory usage is large. By modifying the code slightly, we found that memory can be shared within a single session even if the user does not specify it, thus reducing memory usage.

In the current implementation, the decision to share or not to share memory is based on whether the memory is specified by the user or not.

auto iter = initializers_to_share_map.find(input_name);
bool is_shared_initializer = (iter != initializers_to_share_map.end());
// Caching pre-packed weights is limited to shared initializers associated with the CPU EP for now
if (is_shared_initializer && should_cache_prepacked_weights_for_shared_initializers &&

Even if this conditional branch is removed, memory that should not be shared will not be shared because there will be a conditional branch later in the Murmur hash to check whether the memory contents are the same or not.

const std::string& prepacked_weights_container_key = GenerateKeyForPrepackedWeightsMap(op_type,
weights_to_be_filled_in);
bool container_contains_packed_weight = prepacked_weights_container_->HasWeight(prepacked_weights_container_key);
if (container_contains_packed_weight) {

@take-cheeze
Copy link

I think we should work from don't break anything. So how about adding "share weights aggressively" option to SessionOptions. If it won't break anything in onnxruntime CI, maybe it could be true by default

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.

2 participants