@@ -2136,10 +2136,18 @@ ModelInstanceState::SetInputTensors(
2136
2136
2137
2137
(*input_tensors)[input_index_map_[input_name]] = input_list;
2138
2138
} else {
2139
- // Remove constness to align with the signature of torch::from_blob()
2140
- torch::Tensor input_tensor = torch::from_blob (
2141
- const_cast <char *>(input_buffer), batchn_shape, updated_options);
2142
- (*input_tensors)[input_index_map_[input_name]] = input_tensor;
2139
+ if (batchn_byte_size) {
2140
+ // Remove constness to align with the signature of torch::from_blob()
2141
+ torch::Tensor input_tensor = torch::from_blob (
2142
+ const_cast <char *>(input_buffer), batchn_shape, updated_options);
2143
+ (*input_tensors)[input_index_map_[input_name]] = input_tensor;
2144
+ } else {
2145
+ // torch:from_blob seems not working when the input size is 0
2146
+ // create zero-lenght inputs directly
2147
+ torch::Tensor input_tensor =
2148
+ torch::zeros (batchn_shape, updated_options);
2149
+ (*input_tensors)[input_index_map_[input_name]] = input_tensor;
2150
+ }
2143
2151
}
2144
2152
}
2145
2153
@@ -2168,9 +2176,15 @@ ModelInstanceState::SetInputTensors(
2168
2176
? options.device (torch::kCUDA , device_.index ())
2169
2177
: options.device (torch::kCPU );
2170
2178
2171
- torch::Tensor input_tensor = torch::from_blob (
2172
- const_cast <char *>(dst_buffer), shape, updated_options);
2173
- (*input_tensors)[input_index_map_[input_name]] = input_tensor;
2179
+ if (dst_buffer_byte_size) {
2180
+ torch::Tensor input_tensor = torch::from_blob (
2181
+ const_cast <char *>(dst_buffer), shape, updated_options);
2182
+ (*input_tensors)[input_index_map_[input_name]] = input_tensor;
2183
+ } else {
2184
+ // special handle when input has zero size
2185
+ torch::Tensor input_tensor = torch::zeros (shape, updated_options);
2186
+ (*input_tensors)[input_index_map_[input_name]] = input_tensor;
2187
+ }
2174
2188
}
2175
2189
}
2176
2190
0 commit comments