[bugfix] fix bfloat16 for get_tensor (#1216)
* [bugfix] fix bfloat16 for get_tensor Signed-off-by: Xuchun Shang <xuchun.shang@gmail.com> * update Signed-off-by: Xuchun Shang <xuchun.shang@gmail.com> * update Signed-off-by: Xuchun Shang <xuchun.shang@gmail.com> --------- Signed-off-by: Xuchun Shang <xuchun.shang@gmail.com>
This commit is contained in:
parent
80431fb489
commit
284a3edfec
|
|
@ -378,6 +378,11 @@ class MooncakeStorePyWrapper {
|
|||
}
|
||||
pybind11::object tensor =
|
||||
torch_module().attr("from_numpy")(np_array);
|
||||
if (dtype_enum == TensorDtype::BFLOAT16) {
|
||||
tensor = tensor.attr("view")(torch_module().attr("bfloat16"));
|
||||
} else if (dtype_enum == TensorDtype::FLOAT16) {
|
||||
tensor = tensor.attr("view")(torch_module().attr("float16"));
|
||||
}
|
||||
return tensor;
|
||||
|
||||
} catch (const pybind11::error_already_set &e) {
|
||||
|
|
@ -494,6 +499,13 @@ class MooncakeStorePyWrapper {
|
|||
np_array = np_array.attr("reshape")(shape_tuple);
|
||||
}
|
||||
pybind11::object tensor = torch.attr("from_numpy")(np_array);
|
||||
if (dtype_enum == TensorDtype::BFLOAT16) {
|
||||
tensor =
|
||||
tensor.attr("view")(torch_module().attr("bfloat16"));
|
||||
} else if (dtype_enum == TensorDtype::FLOAT16) {
|
||||
tensor =
|
||||
tensor.attr("view")(torch_module().attr("float16"));
|
||||
}
|
||||
results_list.append(tensor);
|
||||
}
|
||||
} catch (const pybind11::error_already_set &e) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue