Spaces:
Sleeping
Sleeping
Early return for zero size calls to get_tensor. (llama/5482)
Browse files* Early return for zero size calls to get_tensor.
Signed-off-by: Adam Treat <[email protected]>
* Update ggml-kompute.cpp
Co-authored-by: Georgi Gerganov <[email protected]>
* Update ggml-kompute.cpp
Co-authored-by: Georgi Gerganov <[email protected]>
* Add an early return to the get/set tensor when the size is null.
Signed-off-by: Adam Treat <[email protected]>
* Early return after the assertions.
Signed-off-by: Adam Treat <[email protected]>
* Since we do the early return in the generic backend now no reason to do so here as well.
Signed-off-by: Adam Treat <[email protected]>
---------
Signed-off-by: Adam Treat <[email protected]>
Co-authored-by: Georgi Gerganov <[email protected]>
- ggml-backend.c +8 -0
ggml-backend.c
CHANGED
|
@@ -219,6 +219,10 @@ GGML_CALL void ggml_backend_tensor_set(struct ggml_tensor * tensor, const void *
|
|
| 219 |
GGML_ASSERT(buf != NULL && "tensor buffer not set");
|
| 220 |
GGML_ASSERT(offset + size <= ggml_nbytes(tensor) && "tensor write out of bounds");
|
| 221 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 222 |
tensor->buffer->iface.set_tensor(buf, tensor, data, offset, size);
|
| 223 |
}
|
| 224 |
|
|
@@ -229,6 +233,10 @@ GGML_CALL void ggml_backend_tensor_get(const struct ggml_tensor * tensor, void *
|
|
| 229 |
GGML_ASSERT(tensor->buffer != NULL && "tensor buffer not set");
|
| 230 |
GGML_ASSERT(offset + size <= ggml_nbytes(tensor) && "tensor read out of bounds");
|
| 231 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 232 |
tensor->buffer->iface.get_tensor(buf, tensor, data, offset, size);
|
| 233 |
}
|
| 234 |
|
|
|
|
| 219 |
GGML_ASSERT(buf != NULL && "tensor buffer not set");
|
| 220 |
GGML_ASSERT(offset + size <= ggml_nbytes(tensor) && "tensor write out of bounds");
|
| 221 |
|
| 222 |
+
if (!size) {
|
| 223 |
+
return;
|
| 224 |
+
}
|
| 225 |
+
|
| 226 |
tensor->buffer->iface.set_tensor(buf, tensor, data, offset, size);
|
| 227 |
}
|
| 228 |
|
|
|
|
| 233 |
GGML_ASSERT(tensor->buffer != NULL && "tensor buffer not set");
|
| 234 |
GGML_ASSERT(offset + size <= ggml_nbytes(tensor) && "tensor read out of bounds");
|
| 235 |
|
| 236 |
+
if (!size) {
|
| 237 |
+
return;
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
tensor->buffer->iface.get_tensor(buf, tensor, data, offset, size);
|
| 241 |
}
|
| 242 |
|