microsoft / onnxruntime-genai

Generative AI extensions for onnxruntime
MIT License
450 stars 108 forks source link

Fail to build win64 onnxruntime-genai-directml from source #676

Closed shane-huang closed 2 months ago

shane-huang commented 3 months ago

Hello team,

I'm trying to build a Win64 Python wheel from source using this guide. But after the build finishes, I only get a Win32 wheel named onnxruntime_genai_directml-0.4.0.dev0-cp311-cp311-win32.whl. What's odd is that the .pyd file in build\Windows\Release\wheel\onnxruntime_genai looks like it's 64-bit, named onnxruntime_genai.cp311-win_amd64.pyd. See full contents in the folder below:

Additional information you may need:

Could you please kindly guide me on how to correctly build a Win64 python wheel?

natke commented 3 months ago

Hi @shane-huang, that is indeed strange. Are you using a virtual python environment? If so, which one? venv or conda or something different?

Can you list the packages in your python environment?

And can you attach the entire build output from the python build.py command that you run?

baijumeswani commented 2 months ago

Could you please paste the output of this command from your terminal?

where cl.exe

For me, it gives the following:

C:\Program Files\Microsoft Visual Studio\2022\Enterprise>where cl.exe
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.40.33807\bin\Hostx64\x64\cl.exe

Notice the x64 in the path to cl.exe. If your console gives you x86 in the path, it would indicate that you're using the incorrect cl.exe to compile the program.

Try using a x64 console (maybe search for x64 Native Tools Command Prompt in windows and use that console for compilation).

shane-huang commented 2 months ago

I am using Developer Powershell for VS 2022 for building (Community version).

I tried executing cl.exe and got the message saying it's for x86. And I found my x64 compiler at location "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\bin\Hostx64\x64\c1.exe" - when executing it I got the message saying it's for x64. So it does seem I'm using 32 bit compiler as default.

Then I stuck at changing the the default compiler in Powershell from x86 to x64. I tried:

  1. add the x64 cl.exe path to the front of the system Path variable and restart the Powershell, it does not work.
  2. use & "'C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat" x64 and " & 'C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat'". Both give me the message [vcvarsall.bat] Environment initialized for: 'x64'. But when executing cl.exe. It still says for "x86".
baijumeswani commented 2 months ago

Can you open this console and build from there?

x64 Native Tools Command Prompt for VS 2022

image

shane-huang commented 2 months ago

I found this x64 Command Prompt and checked it does use x64 cl.exe. I will try building my wheel with it.

baijumeswani commented 2 months ago

@shane-huang hope the above worked for you. Will close this issue now. Please let us know if that didn't help.