karpathy / llm.c

LLM training in simple, raw C/CUDA

Repository from Github https://github.comkarpathy/llm.cRepository from Github https://github.comkarpathy/llm.c

make: *** [Makefile:194: train_gpt2] Error 2 on Windows

yuyalun-allen opened this issue · comments

I'm trying to run llm.c on Windows, so I add cl.exe from Visual Studio to path and try to execute:

make train_gpt2

But something wiered happens that cl give the error:
图片
The errors in Chinese in the picture mainly mean "Unknown option /OU" etc. But in the command which Makefile generate, there is actually NO option named "/OU". Others errors mean "Unrecognized source file type C:/Users/admin/scoop/apps/git/2.42.0/Idev, supposing object file". So why does cl assumes that "/Idev" is a filepath rather than option?

when I manually execute the command

cl /Idev /Zi /nologo /Wall /WX- /diagnostics:column /sdl /O2 /Oi /Ot /GL /D _DEBUG /D _CONSOLE /D _UNICODE /D UNICODE /Gm- /EHsc /MD /GS /Gy /fp:fast /Zc:wchar_t /Zc:forScope /Zc:inline /permissive- /external:W3 /Gd /TP /wd4996 /Fdtrain_gpt2.pdb /FC /openmp:llvm   train_gpt2.c  /link /OUT:train_gpt2 && copy /Y train_gpt2 train_gpt2.exe

图片

It says "cannot open include file stdio.h".

I'm sorry for my shallow knowlegde about C and Makefile. But is there any error with my configuration? How can I make this run?

@yuyalun-allen - first thing you want to do is this for the Makefile:

https://learn.microsoft.com/en-us/cpp/build/how-to-enable-a-64-bit-visual-cpp-toolset-on-the-command-line?view=msvc-170

Makefiles run on the command line so you'll want your VS compiler environment set up properly. Please make sure and install the Cuda 12.4.1 toolkit if you have an Nvidia GPU in your system too.

@rosslwheeler Thanks for your reply! I've tried to run the command make train_gpt2 within "x64 Native Tools Command Prompt" as the document suggested, and I don't use cuda since I have no Nvidia GPU. But the same error occurs:
图片

It seems that Makefile is able to call cl, but cl parsed the flag wieredly and it cannot find the proper head files. BTW, I used mingw64 in previous projects with makefile and everything was going on well.

What's your error on the above build in the VS command prompt?

There are four kinds of errors or warnings:

  1. cl: command line warning D9035: The 'Og' option is deprecated and will be removed in a future release
  2. cl: command line warning D9002: ignore unkown option "/OU" (etc.)
  3. cl: command line warning D9024: Unrecognized source file type 'C:/Users/.../(etc.)' assume object file
  4. train_gpt2.c(19,10): fatal error C1083: unable to open include file: “unistd.h”: No such file or directory

The above command line you show - cl /Idev ... - will pick up unistd.h which is located in dev. Can you check your repo to see if it's there in dev\unistd.h? You can ignore the warnings...

Oh, I see. Thank you! Execute the make train_gpt2 still not work, but this time when I manually copy and execute the command in the vs prompt:

cl /Idev /Zi /nologo /Wall /WX- /diagnostics:column /sdl /O2 /Oi /Ot /GL /D _DEBUG /D _CONSOLE /D _UNICODE /D UNICODE /Gm- /EHsc /MD /GS /Gy /fp:fast /Zc:wchar_t /Zc:forScope /Zc:inline /permissive- /external:W3 /Gd /TP /wd4996 /Fdtrain_gpt2.pdb /FC /openmp:llvm   train_gpt2.c  /link /OUT:train_gpt2 && copy /Y train_gpt2 train_gpt2.exe

It build successfully.
That's exactly what confused me :( "/Idev" should mean include the "dev" directory, but cl wrongly took it as a input path when execute the make command. However, when I manually execute the command, it interpret it correctly instead.