TorchSharp icon indicating copy to clipboard operation
TorchSharp copied to clipboard

bfloat16 tensor cannot be printed

Open williamlzw opened this issue 1 year ago • 1 comments

var a = torch.randn(3, 3).to(torch.bfloat16); a.print();

williamlzw avatar Apr 10 '25 04:04 williamlzw

Cannot be printed because is not implemented in torchsharp the Half (float16) and BFloat16 and the print is not implemented with these dtype so i make them support on my branch autocast i showed the result in the last comment of this in this PR

FAQ: Why i don't see that PR with committ Support bfloat16? Because i have some problem that i worked on my branch autocast and the PR is based on my main branch not autocast branch

How i can do this my self?

  • Try git clone my forked repo torchsharp and switch to my branch autocast (warning: I didn't run Unit Test so be carefully)
  • Download from official pytorch web the Libtorch and unzip
  • run dotnet build /p:SkipNative=true
  • cd on src\Native and run build.cmd Release x64 --libtorchpath "*FULLPATH OF LIBTORCH\libtorch-win-shared-with-deps-2.8.0+cu128\libtorch\share\cmake\Torch" if you want Debug change the Release to Debug At the end you have all binaries that you need TorchSharp.dll and Libtorchsharp.dll don't forget to copy all .dll of libtorch from lib folder to where your program is located including your TorchSharp.dll and Libtorchsharp.dll. The .dll of libtorch is located in subfolder of lib for example libtorch-win-shared-with-deps-debug-2.8.0+cu128\libtorch\lib

i was try to make work the dotnet build /p:CustomLibTorchPath="Full path of libtorch" for some reason this not compile the libtorch i need research that, i make them worked but now no. I don't know why.

EDIT: I figure out how run CustomLibTorchFullPath. U can do this dotnet build /p:CustomLibTorchFullPath="*FullPath where you downloaded the libtorch*\libtorch-win-shared-with-deps-debug-2.8.0+cu128\libtorch\share\cmake\Torch" and the other steps is not neccesary

haytham2597 avatar Sep 15 '25 17:09 haytham2597