Skip to content

Commit 1808824

Browse files
committed
Address comments
1 parent 0f1659a commit 1808824

File tree

4 files changed

+22
-65
lines changed

4 files changed

+22
-65
lines changed

backends/aoti/common_shims.cpp

Lines changed: 13 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -50,36 +50,14 @@ AOTITorchError aoti_torch_get_storage_offset(
5050
}
5151

5252
AOTITorchError aoti_torch_get_strides(Tensor* tensor, int64_t** ret_strides) {
53-
auto it = internal::tensor_to_strides.find(tensor);
54-
bool needs_update = false;
55-
56-
if (it == internal::tensor_to_strides.end()) {
57-
needs_update = true;
58-
} else {
59-
// Check if cached values are still valid
60-
auto tensor_strides = tensor->strides();
61-
if (it->second.size() != static_cast<size_t>(tensor->dim())) {
62-
needs_update = true;
63-
} else {
64-
for (int i = 0; i < tensor->dim(); i++) {
65-
if (it->second[i] != tensor_strides[i]) {
66-
needs_update = true;
67-
break;
68-
}
69-
}
70-
}
71-
}
72-
73-
if (needs_update) {
74-
std::vector<int64_t> strides(tensor->dim());
75-
auto tensor_strides = tensor->strides();
76-
for (int i = 0; i < tensor->dim(); i++) {
77-
strides[i] = tensor_strides[i];
78-
}
79-
it =
80-
internal::tensor_to_strides.insert_or_assign(tensor, std::move(strides))
81-
.first;
53+
std::vector<int64_t> strides(tensor->dim());
54+
auto tensor_strides = tensor->strides();
55+
for (ssize_t i = 0; i < tensor->dim(); i++) {
56+
strides[i] = static_cast<int64_t>(tensor_strides[i]);
8257
}
58+
auto it =
59+
internal::tensor_to_strides.insert_or_assign(tensor, std::move(strides))
60+
.first;
8361

8462
// For 0D tensors, data() returns nullptr on empty vectors, but we need to
8563
// return a valid pointer
@@ -100,35 +78,13 @@ AOTITorchError aoti_torch_get_dtype(Tensor* tensor, int32_t* ret_dtype) {
10078
}
10179

10280
AOTITorchError aoti_torch_get_sizes(Tensor* tensor, int64_t** ret_sizes) {
103-
auto it = internal::tensor_to_sizes.find(tensor);
104-
bool needs_update = false;
105-
106-
if (it == internal::tensor_to_sizes.end()) {
107-
needs_update = true;
108-
} else {
109-
// Check if cached values are still valid
110-
auto tensor_sizes = tensor->sizes();
111-
if (it->second.size() != static_cast<size_t>(tensor->dim())) {
112-
needs_update = true;
113-
} else {
114-
for (int i = 0; i < tensor->dim(); i++) {
115-
if (it->second[i] != tensor_sizes[i]) {
116-
needs_update = true;
117-
break;
118-
}
119-
}
120-
}
121-
}
122-
123-
if (needs_update) {
124-
std::vector<int64_t> sizes(tensor->dim());
125-
auto tensor_sizes = tensor->sizes();
126-
for (int i = 0; i < tensor->dim(); i++) {
127-
sizes[i] = tensor_sizes[i];
128-
}
129-
it = internal::tensor_to_sizes.insert_or_assign(tensor, std::move(sizes))
130-
.first;
81+
std::vector<int64_t> sizes(tensor->dim());
82+
auto tensor_sizes = tensor->sizes();
83+
for (ssize_t i = 0; i < tensor->dim(); i++) {
84+
sizes[i] = static_cast<int64_t>(tensor_sizes[i]);
13185
}
86+
auto it = internal::tensor_to_sizes.insert_or_assign(tensor, std::move(sizes))
87+
.first;
13288

13389
// For 0D tensors, data() returns nullptr on empty vectors, but we need to
13490
// return a valid pointer

backends/cuda/runtime/cuda_backend.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ class ET_EXPERIMENTAL CudaBackend final
170170
// static/singleton across the whole process. When we share multiple methods
171171
// (meaning multiple so_handle) in the same process, we need to re-register
172172
// the symbols from the so_handle that is being used in this execution.
173-
register_shared_library_functions(handle->so_handle);
173+
ET_CHECK_OK_OR_RETURN_ERROR(
174+
register_shared_library_functions(handle->so_handle));
174175

175176
size_t n_inputs;
176177
AOTInductorModelContainerGetNumInputs(handle->container_handle, &n_inputs);

extension/llm/runner/multimodal_prefiller.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ Result<uint64_t> MultimodalPrefiller::prefill(
6767
InvalidArgument,
6868
"Model expects uint8_t image data, but image has float data.");
6969
} else {
70-
ET_LOG(
71-
Error,
70+
ET_CHECK_OR_RETURN_ERROR(
71+
false,
72+
NotSupported,
7273
"Unsupported image encoder input dtype: %s",
7374
::executorch::runtime::toString(expected_dtype));
74-
return ::executorch::runtime::Error::NotSupported;
7575
}
7676

7777
// The model might expect a 4D tensor (NCHW), but toTensor() returns a 3D
@@ -119,12 +119,12 @@ Result<uint64_t> MultimodalPrefiller::prefill(
119119
convert_to_bfloat16(audio_tensor),
120120
"Failed to convert audio tensor to bfloat16");
121121
} else {
122-
ET_LOG(
123-
Error,
122+
ET_CHECK_OR_RETURN_ERROR(
123+
false,
124+
NotSupported,
124125
"Unsupported audio encoder input dtype: %s. Expecting %s",
125126
::executorch::runtime::toString(audio_tensor->scalar_type()),
126127
::executorch::runtime::toString(expected_dtype));
127-
return ::executorch::runtime::Error::NotSupported;
128128
}
129129
}
130130

extension/llm/runner/util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ inline runtime::Result<TensorPtr> populate_start_pos_or_cache_position(
145145
* Helper function to convert a float tensor to bfloat16.
146146
* Creates a new tensor with bfloat16 dtype and copies/converts the data.
147147
*/
148-
::executorch::runtime::Result<::executorch::extension::TensorPtr>
148+
inline ::executorch::runtime::Result<::executorch::extension::TensorPtr>
149149
convert_to_bfloat16(const ::executorch::extension::TensorPtr& src_tensor) {
150150
ET_CHECK_OR_RETURN_ERROR(
151151
src_tensor->scalar_type() == ::executorch::aten::ScalarType::Float,

0 commit comments

Comments
 (0)