TensorRT-LLM icon indicating copy to clipboard operation
TensorRT-LLM copied to clipboard

Support cpu inference with scaffolding

Open WeiHaocheng opened this issue 1 year ago • 21 comments

Many community contributors find it difficult to find GPU based development environments and prefer CPU based scaffolding workers to complete some development tasks. Potential options include pytorch, ollama, llama.cpp.

WeiHaocheng avatar Apr 07 '25 13:04 WeiHaocheng

@WeiHaocheng, I'm interested in working on this issue - can this be assigned to me?

amemov avatar Apr 08 '25 11:04 amemov

@WeiHaocheng

amemov avatar Apr 17 '25 16:04 amemov

@amemov Great, assign to you~ Feel free to left comment if you have any idea about this issue. The introduction and code of scaffolding is here: https://github.com/NVIDIA/TensorRT-LLM/blob/main/tensorrt_llm/scaffolding/README.md

We would like to develop a Worker which can support inference on cpu.

The code for Worker is here: https://github.com/NVIDIA/TensorRT-LLM/blob/main/tensorrt_llm/scaffolding/worker.py

WeiHaocheng avatar Apr 22 '25 04:04 WeiHaocheng

@amemov Great, assign to you~ Feel free to left comment if you have any idea about this issue. The introduction and code of scaffolding is here: https://github.com/NVIDIA/TensorRT-LLM/blob/main/tensorrt_llm/scaffolding/README.md

We would like to develop a Worker which can support inference on cpu.

The code for Worker is here: https://github.com/NVIDIA/TensorRT-LLM/blob/main/tensorrt_llm/scaffolding/worker.py

@WeiHaocheng , just wanted to double check that I'm on the right track: I looked at the code more in-depth and if I understood correctly I need to write a class for worker.py. I looked into the potential options that you mentioned above - they all seem pretty straightforward. For now I will focus on writing implementation with Pytorch.

About testing: I see that there is tests/unittest/scaffolding/test_worker.py ; I suppose my test should be similar to test_trtllm_worker_generation?

amemov avatar Apr 28 '25 01:04 amemov

@amemov

Yes, your understanding is right. We need a Worker likes "PytorchWorker" and it can handle and process the GenerationTask in CPU.

And you can read the README and just add a directory on "tensorrt_llm/scaffolding/contrib" and add an example of running the worker on "example/scaffolding/contrib". I would migrate it into worker.py and add the tests in later. We plan to use this approach to ensure flexible and scalable for contributors.

WeiHaocheng avatar Apr 28 '25 02:04 WeiHaocheng

Hi @amemov ~ May I ask if your progress is still going smoothly? If you encounter some difficult problems during the building, maybe you can try downloading the pre-compiled image directly from my dockerhub.

https://hub.docker.com/r/weihaocheng2/tensorrt_llm

Feel free to contact me if you got any problem.

WeiHaocheng avatar May 14 '25 04:05 WeiHaocheng

Hi @WeiHaocheng - I'm still working on it. I had to take a long break due to personal issues. I think I will have a PR draft ready closer to the end of this week.

amemov avatar May 15 '25 01:05 amemov

Hi @WeiHaocheng - I'm still working on it. I had to take a long break due to personal issues. I think I will have a PR draft ready closer to the end of this week.

Thank you. Feel free to tell me if you need any help~

WeiHaocheng avatar May 15 '25 01:05 WeiHaocheng

Hi @WeiHaocheng - I created a draft PR, and I was wondering if there is any doc in the documentation or on Nvidia website that outlines how exactly the project has to be built from scratch and what steps need to be taken prior to testing the Python code?

What would you recommend? If using the Docker image that you mentioned above, which one should I download? I tried so far downloading with_wheel_9830 and devel_with_release, but I still wasn't able to figure out what I was doing wrong and why I couldn't run my example file

amemov avatar May 25 '25 15:05 amemov

Hi @WeiHaocheng - I created a draft PR, and I was wondering if there is any doc in the documentation or on Nvidia website that outlines how exactly the project has to be built from scratch and what steps need to be taken prior to testing the Python code?

What would you recommend? If using the Docker image that you mentioned above, which one should I download? I tried so far downloading with_wheel_9830 and devel_with_release, but I still wasn't able to figure out what I was doing wrong and why I couldn't run my example file

Hi @amemov . You can see the whole build step from here

Overall, the development process for deploying Python can be divided into three steps:

  • Build the docker image from source. (mainly "make -C docker release_run")
  • Build the cpp code and wheel package. (mainly "python3 ./scripts/build_wheel.py")
  • Bind the python path to your source code. (mainly "pip install -e .")

Due to the potential inconvenience that the first two steps may cause for some contributors, I have packaged an image that has already completed the first two steps(with_wheel_9830). When you come into the docker, you can directly run the step 3 on your source code path:

"TRTLLM_PRECOMPILED_LOCATION=/app/tensorrt_llm-0.20.0rc2-cp312-cp312-linux_x86_64.whl pip install -e ."

Then you can run the example on "examples/scaffolding".

Please feel free to paste the errors you encountered. And maybe you can give us a link to your draft PR if you feel that the idea is already clear~

CC @dc3671

WeiHaocheng avatar May 26 '25 02:05 WeiHaocheng

Hi @WeiHaocheng - I created a draft PR, and I was wondering if there is any doc in the documentation or on Nvidia website that outlines how exactly the project has to be built from scratch and what steps need to be taken prior to testing the Python code?

What would you recommend? If using the Docker image that you mentioned above, which one should I download? I tried so far downloading with_wheel_9830 and devel_with_release, but I still wasn't able to figure out what I was doing wrong and why I couldn't run my example file

Hi @amemov . You can see the whole build step from here

Overall, the development process for deploying Python can be divided into three steps:

  • Build the docker image from source. (mainly "make -C docker release_run")
  • Build the cpp code and wheel package. (mainly "python3 ./scripts/build_wheel.py")
  • Bind the python path to your source code. (mainly "pip install -e .")

Due to the potential inconvenience that the first two steps may cause for some contributors, I have packaged an image that has already completed the first two steps(with_wheel_9830). When you come into the docker, you can directly run the step 3 on your source code path:

"TRTLLM_PRECOMPILED_LOCATION=/app/tensorrt_llm-0.20.0rc2-cp312-cp312-linux_x86_64.whl pip install -e ."

Then you can run the example on "examples/scaffolding".

Please feel free to paste the errors you encountered. And maybe you can give us a link to your draft PR if you feel that the idea is already clear~

CC @dc3671

Thank you, I will try using your image one more time - now I see what I was doing wrong.

I opened a draft PR #4639, but I still need to verify that it actually works.

amemov avatar May 26 '25 02:05 amemov

@amemov I found that the dependency of main branch did a update recently(May 19), so the image(with_wheel_9830) can not work with top commit of main branch.

I will update the new image today or tomorrow to my dockerhub. Or you need to reset the commit of main branch back to May 18 or before.

WeiHaocheng avatar May 26 '25 08:05 WeiHaocheng

@WeiHaocheng I tried using your latest docker image - and I'm still getting an error when I do the last step with the wheel

Detected profile: [settings] arch=x86_64 build_type=Release compiler=gcc compiler.cppstd=gnu17 compiler.libcxx=libstdc++11 compiler.version=13 os=Linux
WARN: This profile is a guess of your environment, please check it. WARN: The output of this command is not guaranteed to be stable and can change in future Conan versions. 
WARN: Use your own profile files for stability. Saving detected profile to /root/.conan2/profiles/default CMake Build command: cmake --build . --config Release --parallel 8 --target build_wheel_targets gmake: Makefile: No such file or directory gmake: *** No rule to make target 'Makefile'. Stop. 
Traceback (most recent call last): 
File "/code/tensorrt_llm/./scripts/build_wheel.py", line 703, in <module> main(**vars(args)) 
File "/code/tensorrt_llm/./scripts/build_wheel.py", line 382, in main build_run(cmake_build_command) 
File "/usr/lib/python3.12/subprocess.py", line 571, in run raise CalledProcessError(retcode, process.args, subprocess.CalledProcessError: 
Command 'cmake --build . --config Release --parallel 8 --target build_wheel_targets ' returned non-zero exit status 2.

I guess I will try building the image on my computer and trying to see that would potentially work - the only problem is that I don't have so much free disk space on my machine, but I will see what I can do

amemov avatar May 28 '25 18:05 amemov

@amemov You can tried this new image: docker pull weihaocheng2/tensorrt_llm:with_wheel_b6f5

What is the command you run and where is the path you run?

WeiHaocheng avatar May 29 '25 02:05 WeiHaocheng

@WeiHaocheng / @amemov Is the issue solved? If not, can I help?

therealnaveenkamal avatar Jul 27 '25 00:07 therealnaveenkamal

Hi @WeiHaocheng I'm interested in taking up this issue. Could you assign it to me?

nikJ13 avatar Mar 19 '26 15:03 nikJ13

@nikJ13 / @therealnaveenkamal feel free to take it

amemov avatar Mar 19 '26 15:03 amemov

So I believe my PR #12256 fixes this issue. Shall I link it to this issue?

nikJ13 avatar Mar 19 '26 17:03 nikJ13

@nikJ13 , feel free to bring that up in your PR and ask maintainers

amemov avatar Mar 25 '26 17:03 amemov

So I believe my PR #12256 fixes this issue. Shall I link it to this issue?

@nikJ13 Yes~ I think so. Please link them.

WeiHaocheng avatar Mar 27 '26 07:03 WeiHaocheng