已合并
[sync] PR-39043: [fix] 连续性判断 #39102
[sync] PR-39043: [fix] 连续性判断 #39102
已合并
ascend-robot创建于 6月23日
1 个文件变更+4-1
@@ -19,6 +19,8 @@ def npu_combine_tensors(list_of_tensor, require_copy_value=True):
19 if tensor.device.type != "npu":19 if tensor.device.type != "npu":
20 raise RuntimeError("Tensors to combine must be on NPU, got {}.".format(tensor.device.type) +20 raise RuntimeError("Tensors to combine must be on NPU, got {}.".format(tensor.device.type) +
21 pta_error(ErrCode.VALUE))21 pta_error(ErrCode.VALUE))
22+ if not tensor.is_contiguous():
23+ raise RuntimeError("Tensors to combine must be contiguous." + pta_error(ErrCode.VALUE))
22 total_numel += torch_npu.get_storage_size(tensor)24 total_numel += torch_npu.get_storage_size(tensor)
23 25 
24 if total_numel == 0:26 if total_numel == 0:
@@ -68,7 +70,8 @@ def is_combined_tensor_valid(combined_tensor, list_of_tensor):
68 for tensor in list_of_tensor:70 for tensor in list_of_tensor:
69 if tensor is None or \71 if tensor is None or \
70 tensor.data_ptr() < combined_tensor_start_addr or \72 tensor.data_ptr() < combined_tensor_start_addr or \
71- tensor.data_ptr() >= combined_tensor_end_addr:73+ tensor.data_ptr() >= combined_tensor_end_addr or \
74+ not tensor.is_contiguous():
72 return False75 return False
73 76 
74 return True77 return True