Is there a way to downcast a float32 tensor to a float16 tensor? #675
-
I'm reverse engineering a pytorch network so I want numbers to exactly match. For some reason pytorch conv1d is automatically turning float32 input tensors into a float16 output tensor, I'm doing analogous transformations with the float32 tensors in ggml, but I'd like to immediately cast the resulting fp32 tensor to fp16 afterward to see if I get the numbers to exactly match. Is there a recommended way to do this, or would I need to add it? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You can use ggml_cpy(ctx, src, ggml_new_tensor(ctx, GGML_TYPE_F32, 4, src->ne)); There are also functions defined in |
Beta Was this translation helpful? Give feedback.
You can use
ggml_cpy
to convert tensors to a different data type, you would need to create a tensor with the same dimensions and a different type and specify it as the destination of the copy. For example:There are also functions defined in
ggml.h
to convert data between fp16 and fp32,ggml_fp16_to_fp32
andggml_fp16_to_fp32_row
.