-
Notifications
You must be signed in to change notification settings - Fork 9.2k
[HiCache] Support host memory size smaller than device memory size #16909
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
Changes from all commits
3d9f693
cbfb249
c9a93ad
2f80b3a
35fd328
cf0af9a
f6005cf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -907,8 +907,12 @@ def evict(self, params: EvictParams) -> EvictResult: | |
| if not x.backuped: | ||
| if self.cache_controller.write_policy == "write_back": | ||
| # write to host if the node is not backuped | ||
| num_evicted += self.write_backup(x, write_back=True) | ||
| write_back_nodes.append(x) | ||
| backed_up_len = self.write_backup(x, write_back=True) | ||
| if backed_up_len > 0: | ||
| num_evicted += backed_up_len | ||
| write_back_nodes.append(x) | ||
| else: | ||
| num_evicted += self._evict_regular(x) | ||
| else: | ||
| num_evicted += self._evict_regular(x) | ||
| else: | ||
|
|
@@ -977,22 +981,28 @@ def evict_host(self, num_tokens: int): | |
| if x.host_ref_counter > 0: | ||
| continue | ||
|
|
||
| if x.host_value is None: | ||
| continue | ||
|
|
||
| # Block deleted entirely (GPU already evicted, now CPU freed) -- | ||
| # emit BlockRemoved so the router removes this block from its index. | ||
| self._record_remove_event(x) | ||
| num_evicted += self.cache_controller.evict_host(x.host_value) | ||
| x.host_value = None | ||
|
|
||
| if x.evicted: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does this mean we can't evict the host if the data is present on GPU?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Data in L2 should be consistent with the GPU. |
||
| key = self.get_child_key_fn(x.key) | ||
| v = x.parent.children.pop(key, None) | ||
| assert v == x, f"parent does not have child key, {key}" | ||
|
|
||
| if len(x.parent.children) == 0 and x.parent.evicted: | ||
| new_priority = self.eviction_strategy.get_priority(x.parent) | ||
| heapq.heappush(eviction_heap, (new_priority, x.parent)) | ||
|
|
||
| key = self.get_child_key_fn(x.key) | ||
| v = x.parent.children.pop(key, None) | ||
| assert v == x, f"parent does not have child key, {key}" | ||
| if x in self.evictable_host_leaves: | ||
| self.evictable_host_leaves.remove(x) | ||
| self._update_host_leaf_status(x.parent) | ||
|
|
||
| if len(x.parent.children) == 0 and x.parent.evicted: | ||
| new_priority = self.eviction_strategy.get_priority(x.parent) | ||
| heapq.heappush(eviction_heap, (new_priority, x.parent)) | ||
|
|
||
| def load_back( | ||
| self, node: TreeNode, mem_quota: Optional[int] = None | ||
| ) -> Optional[torch.Tensor]: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -165,9 +165,9 @@ def __init__( | |
| self.start_layer = device_pool.start_layer | ||
| self.end_layer = device_pool.end_layer | ||
|
|
||
| assert ( | ||
| self.size > device_pool.size | ||
| ), "The host memory should be larger than the device memory with the current protocol" | ||
| # assert ( | ||
| # self.size > device_pool.size | ||
| # ), "The host memory should be larger than the device memory with the current protocol" | ||
|
Comment on lines
+168
to
+170
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's only skip this check when write back is selected, or when user specified smaller CPU memory size, fall back to write back policy
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, we need a check here |
||
|
|
||
| # Verify there is enough available host memory. | ||
| host_mem = psutil.virtual_memory() | ||
|
|
||
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 magic numbers
0.8and0.5for calculatingprefetch_capacity_limitshould be defined as named constants at the module level to improve readability and maintainability. For example,PREFETCH_CAPACITY_FACTOR_LARGE_HOST = 0.8andPREFETCH_CAPACITY_FACTOR_SMALL_HOST = 0.5.