-
Notifications
You must be signed in to change notification settings - Fork 0
Pr1192 test #6
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
base: main
Are you sure you want to change the base?
Pr1192 test #6
Changes from all commits
5b6141c
1cb3fd9
55f2b35
2d1f66e
4a602dd
7710605
469da73
915b40f
9daaa97
360e5c8
6e373f2
41befb1
ea67873
eb530ff
cfe61f0
1c8ad1b
de71fe2
3ac809a
68db916
3cfa936
6b80b41
e21faca
3e63ac1
40f1bc6
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 |
|---|---|---|
|
|
@@ -1004,6 +1004,91 @@ def batch_get_tensor_with_tp(self, base_keys: List[str], tp_rank: int = 0, tp_si | |
|
|
||
| --- | ||
|
|
||
| ### PyTorch Tensor Operations (Zero Copy) | ||
|
|
||
| These methods provide direct support for storing and retrieving PyTorch tensors. They automatically handle serialization and metadata, and include built-in support for **Tensor Parallelism (TP)** by automatically splitting and reconstructing tensor shards. | ||
|
|
||
| ⚠️ **Note**: These methods require `torch` to be installed and available in the environment. | ||
|
|
||
| #### get_tensor_into() | ||
|
|
||
| Get a PyTorch tensor from the store directly into a pre-allocated buffer. | ||
|
|
||
| ```python | ||
| def get_tensor_with_tp(self, key: str, buffer_ptr: int, size: int) -> torch.Tensor | ||
| ``` | ||
|
|
||
| **Parameters:** | ||
|
|
||
| - `key` (str): Base identifier of the tensor. | ||
| - `buffer_ptr` (int): The buffer pointer pre-allocated for tensor, and the buffer should be registered. | ||
| - `size` (int): The size of buffer. | ||
|
|
||
| **Returns:** | ||
|
|
||
| - `torch.Tensor`: The retrieved tensor (or shard). Returns `None` if not found. | ||
|
|
||
| #### batch_get_tensor() | ||
|
|
||
| Get a batch of PyTorch tensor from the store directly into a pre-allocated buffer. | ||
|
|
||
| ```python | ||
| def batch_get_tensor_with_tp(self, base_keys: List[str], buffer_ptrs: List[int], sizes: List[int]) -> List[torch.Tensor] | ||
| ``` | ||
|
|
||
| **Parameters:** | ||
|
|
||
| - `base_keys` (List[str]): List of base identifiers. | ||
| - `buffer_ptrs` (List[int]): List of the buffers pointer pre-allocated for tensor, and the buffers should be registered. | ||
| - `sizes` (List[int]): List of the size of buffers. | ||
|
|
||
| **Returns:** | ||
|
|
||
| - `List[torch.Tensor]`: List of retrieved tensors (or shards). Contains `None` for missing keys. | ||
|
|
||
| #### get_tensor_into_with_tp() | ||
|
|
||
| Get a PyTorch tensor from the store, specifically retrieving the shard corresponding to the given Tensor Parallel rank, directly into the pre-allocated buffer. | ||
|
|
||
| ```python | ||
| def get_tensor_with_tp(self, key: str, buffer_ptr: int, size: int, tp_rank: int = 0, tp_size: int = 1, split_dim: int = 0) -> torch.Tensor | ||
| ``` | ||
|
|
||
| **Parameters:** | ||
|
|
||
| - `key` (str): Base identifier of the tensor. | ||
| - `buffer_ptr` (int): The buffer pointer pre-allocated for tensor, and the buffer should be registered. | ||
| - `size` (int): The size of buffer. | ||
| - `tp_rank` (int): The tensor parallel rank to retrieve (default: 0). Fetches key `key_tp_{rank}` if `tp_size > 1`. | ||
| - `tp_size` (int): Total tensor parallel size (default: 1). | ||
| - `split_dim` (int): The dimension used during splitting (default: 0). | ||
|
|
||
| **Returns:** | ||
|
|
||
| - `torch.Tensor`: The retrieved tensor (or shard). Returns `None` if not found. | ||
|
|
||
|
Comment on lines
+1049
to
+1069
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. Function signature mismatch for The code block shows 🔎 Apply this diff: ```python
-def get_tensor_with_tp(self, key: str, buffer_ptr: int, size: int, tp_rank: int = 0, tp_size: int = 1, split_dim: int = 0) -> torch.Tensor
+def get_tensor_into_with_tp(self, key: str, buffer_ptr: int, size: int, tp_rank: int = 0, tp_size: int = 1, split_dim: int = 0) -> torch.Tensor🧰 Tools🪛 markdownlint-cli2 (0.18.1)1059-1059: Unordered list indentation (MD007, ul-indent) 1060-1060: Unordered list indentation (MD007, ul-indent) 1061-1061: Unordered list indentation (MD007, ul-indent) 1062-1062: Unordered list indentation (MD007, ul-indent) 1063-1063: Unordered list indentation (MD007, ul-indent) 1064-1064: Unordered list indentation (MD007, ul-indent) 1068-1068: Unordered list indentation (MD007, ul-indent) 🤖 Prompt for AI Agents |
||
| #### batch_get_tensor_with_tp() | ||
|
|
||
| Get a batch of PyTorch tensor shards from the store for a given Tensor Parallel rank, directly into the pre-allocated buffer. | ||
|
|
||
| ```python | ||
| def batch_get_tensor_with_tp(self, base_keys: List[str], buffer_ptrs: List[int], sizes: List[int], tp_rank: int = 0, tp_size: int = 1) -> List[torch.Tensor] | ||
| ``` | ||
|
|
||
| **Parameters:** | ||
|
|
||
| - `base_keys` (List[str]): List of base identifiers. | ||
| - `buffer_ptrs` (List[int]): List of the buffers pointer pre-allocated for tensor, and the buffers should be registered. | ||
| - `sizes` (List[int]): List of the size of buffers. | ||
| - `tp_rank` (int): The tensor parallel rank to retrieve (default: 0). | ||
| - `tp_size` (int): Total tensor parallel size (default: 1). | ||
|
|
||
| **Returns:** | ||
|
|
||
| - `List[torch.Tensor]`: List of retrieved tensors (or shards). Contains `None` for missing keys. | ||
|
|
||
|
Comment on lines
+1070
to
+1089
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. Section title should be This section is under "PyTorch Tensor Operations (Zero Copy)" but uses 🔎 Apply this diff:-#### batch_get_tensor_with_tp()
+#### batch_get_tensor_into_with_tp()
Get a batch of PyTorch tensor shards from the store for a given Tensor Parallel rank, directly into the pre-allocated buffer.
```python
-def batch_get_tensor_with_tp(self, base_keys: List[str], buffer_ptrs: List[int], sizes: List[int], tp_rank: int = 0, tp_size: int = 1) -> List[torch.Tensor]
+def batch_get_tensor_into_with_tp(self, base_keys: List[str], buffer_ptrs: List[int], sizes: List[int], tp_rank: int = 0, tp_size: int = 1) -> List[torch.Tensor]🧰 Tools🪛 markdownlint-cli2 (0.18.1)1080-1080: Unordered list indentation (MD007, ul-indent) 1081-1081: Unordered list indentation (MD007, ul-indent) 1082-1082: Unordered list indentation (MD007, ul-indent) 1083-1083: Unordered list indentation (MD007, ul-indent) 1084-1084: Unordered list indentation (MD007, ul-indent) 1088-1088: Unordered list indentation (MD007, ul-indent) 🤖 Prompt for AI Agents |
||
| --- | ||
|
|
||
| ### Batch Zero-Copy Operations | ||
|
|
||
| #### batch_put_from() | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -62,6 +62,35 @@ static const std::array<ArrayCreatorFunc, 15> array_creators = {{ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| create_typed_array<uint8_t>, // FLOAT8_E5M2 = 14 (using uint8_t as storage) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| template <typename T> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| py::array create_typed_array_view(char *data_ptr, size_t offset, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| size_t total_length) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return py::array_t<T>({static_cast<ssize_t>(total_length / sizeof(T))}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (T *)(data_ptr + offset), py::none()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| static const std::array<ArrayCreatorFunc, 16> array_creators_view = {{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| create_typed_array_view<float>, // FLOAT32 = 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| create_typed_array_view<double>, // FLOAT64 = 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| create_typed_array_view<int8_t>, // INT8 = 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| create_typed_array_view<uint8_t>, // UINT8 = 3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| create_typed_array_view<int16_t>, // INT16 = 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| create_typed_array_view<uint16_t>, // UINT16 = 5 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| create_typed_array_view<int32_t>, // INT32 = 6 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| create_typed_array_view<uint32_t>, // UINT32 = 7 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| create_typed_array_view<int64_t>, // INT64 = 8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| create_typed_array_view<uint64_t>, // UINT64 = 9 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| create_typed_array_view<bool>, // BOOL = 10 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| create_typed_array_view<uint16_t>, // FLOAT16 = 11 (using uint16_t as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // storage) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| create_typed_array_view<uint16_t>, // BFLOAT16 = 12 (using uint16_t as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // storage) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| create_typed_array_view<uint8_t>, // FLOAT8_E4M3 = 13 (using uint8_t as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // storage) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| create_typed_array_view<uint8_t>, // FLOAT8_E5M2 = 14 (using uint8_t as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // storage) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+72
to
+92
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. Size mismatch: Both arrays should map the same 🔎 Apply this diff to fix the size:-static const std::array<ArrayCreatorFunc, 16> array_creators_view = {{
+static const std::array<ArrayCreatorFunc, 15> array_creators_view = {{
create_typed_array_view<float>, // FLOAT32 = 0
create_typed_array_view<double>, // FLOAT64 = 1
create_typed_array_view<int8_t>, // INT8 = 2
create_typed_array_view<uint8_t>, // UINT8 = 3
create_typed_array_view<int16_t>, // INT16 = 4
create_typed_array_view<uint16_t>, // UINT16 = 5
create_typed_array_view<int32_t>, // INT32 = 6
create_typed_array_view<uint32_t>, // UINT32 = 7
create_typed_array_view<int64_t>, // INT64 = 8
create_typed_array_view<uint64_t>, // UINT64 = 9
create_typed_array_view<bool>, // BOOL = 10
create_typed_array_view<uint16_t>, // FLOAT16 = 11 (using uint16_t as
// storage)
create_typed_array_view<uint16_t>, // BFLOAT16 = 12 (using uint16_t as
// storage)
create_typed_array_view<uint8_t>, // FLOAT8_E4M3 = 13 (using uint8_t as
// storage)
create_typed_array_view<uint8_t>, // FLOAT8_E5M2 = 14 (using uint8_t as
// storage)
}};📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| inline TensorDtype get_tensor_dtype(py::object dtype_obj) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (dtype_obj.is_none()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return TensorDtype::UNKNOWN; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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.
Documentation has incorrect function signatures.
The section title is
get_tensor_into()but the code block showsget_tensor_with_tp. Similarly, the next sectionbatch_get_tensor()showsbatch_get_tensor_with_tpin its signature. These appear to be copy-paste errors.🔎 Apply this diff to fix the signatures:
In docs/source/python-api-reference/mooncake-store.md around lines 1013 to 1030,
the function signatures are incorrect: the section titled get_tensor_into()
shows def get_tensor_with_tp(...) and batch_get_tensor() shows def
batch_get_tensor_with_tp(...). Update the signatures to match the section titles
and intended parameter names: rename get_tensor_with_tp to get_tensor_into(self,
key: str, buffer_ptr: int, size: int) -> torch.Tensor, and rename
batch_get_tensor_with_tp to batch_get_tensor_into with the correct parameter
names and types (e.g. keys: List[str], buffer_ptrs: List[int], sizes: List[int])
returning List[torch.Tensor]; ensure surrounding code blocks and descriptions
remain consistent.