Skip to content

Commit 7670ea5

Browse files
dpj135ascend-robot
authored andcommitted
[Bugfix] Fixed YuanrongStorageClient
Co-authored-by: dpj135<diaopengjie@huawei.com> # message auto-generated for no-merge-commit merge: !6 merge dpj/fix_yr into main [Bugfix] Fixed YuanrongStorageClient Created-by: dpj135 Commit-by: dpj135 Merged-by: ascend-robot Description: ## Description We fixed three problems about YuanrongStorageClient : - The import path for datasystem has changed. - `_batch_put` lacks a logic branch when GPU is unavailable. - Tensor serialization has been temporarily optimized using `tensor.clone`. See merge request: Ascend/TransferQueue!6
1 parent 7f70edd commit 7670ea5

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

transfer_queue/storage/clients/yuanrong_client.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
YUANRONG_DATASYSTEM_IMPORTED: bool = True
3333
TORCH_NPU_IMPORTED: bool = True
3434
try:
35-
import datasystem
35+
from yr import datasystem
3636
except ImportError:
3737
YUANRONG_DATASYSTEM_IMPORTED = False
3838

@@ -123,15 +123,17 @@ def _batch_put(self, keys: list[str], values: list[Any]):
123123
cpu_values = []
124124

125125
for key, value in zip(keys, values, strict=True):
126-
if isinstance(value, torch.Tensor) and value.device.type == "npu":
126+
if isinstance(value, Tensor) and value.device.type == "npu":
127127
if not value.is_contiguous():
128128
raise ValueError(f"NPU Tensor is not contiguous: {value}")
129129
npu_keys.append(key)
130130
npu_values.append(value)
131131

132132
else:
133133
cpu_keys.append(key)
134-
cpu_values.append(pickle.dumps(value))
134+
# TODO: Optimize serialization of tensors
135+
# Serializing slice of tensors results in entire tensors being serialized
136+
cpu_values.append(pickle.dumps(value.clone() if isinstance(value, Tensor) else value))
135137

136138
# put NPU data
137139
for i in range(0, len(npu_keys), NPU_DS_CLIENT_KEYS_LIMIT):
@@ -153,7 +155,7 @@ def _batch_put(self, keys: list[str], values: list[Any]):
153155

154156
else:
155157
# All data goes through CPU path
156-
pickled_values = [pickle.dumps(v) for v in values]
158+
pickled_values = [pickle.dumps(v.clone() if isinstance(v, Tensor) else v) for v in values]
157159
for i in range(0, len(keys), CPU_DS_CLIENT_KEYS_LIMIT):
158160
batch_keys = keys[i : i + CPU_DS_CLIENT_KEYS_LIMIT]
159161
batch_vals = pickled_values[i : i + CPU_DS_CLIENT_KEYS_LIMIT]
@@ -248,6 +250,17 @@ def _batch_get(self, keys: list[str], shapes: list, dtypes: list) -> list[Any]:
248250
results[idx] = pickle.loads(raw_val)
249251

250252
return results
253+
else:
254+
# npu is not available, goes through cpu_ds_client
255+
results = [None] * len(keys)
256+
idx = 0
257+
for i in range(0, len(keys), CPU_DS_CLIENT_KEYS_LIMIT):
258+
batch_keys = keys[i : i + CPU_DS_CLIENT_KEYS_LIMIT]
259+
raw_values = self._cpu_ds_client.get(batch_keys)
260+
for raw_val in raw_values:
261+
results[idx] = pickle.loads(raw_val)
262+
idx += 1
263+
return results
251264

252265
def get(self, keys: list[str], shapes=None, dtypes=None) -> list[Any]:
253266
"""Retrieves multiple values from remote storage with expected metadata.

0 commit comments

Comments
 (0)