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

Does qwen3 support lora inference?

Open oppolll opened this issue 1 year ago • 3 comments

Question 1: https://github.com/NVIDIA/TensorRT-LLM/blob/main/tests/unittest/llmapi/test_llm_pytorch.py

I referred to the link above to deploy qwen3 lora, but lora seems not to work. May I ask if qwen3 supports lora inference? The lora inference log is loaded as follows. It seems that lora has been loaded correctly:

[TensorRT-LLM] TensorRT-LLM version: 0.20.0rc3 [TensorRT-LLM][INFO] Refreshed the MPI local session Loading weights: 100%|██████████| 1353/1353 [00:11<00:00, 114.20it/s] Model init total -- 37.49s [TensorRT-LLM][INFO] Max KV cache pages per sequence: 1281 [window size=40961] [TensorRT-LLM][INFO] Number of tokens per block: 32. [TensorRT-LLM][INFO] [MemUsageChange] Allocated 10.01 GiB for max tokens in paged KV cache (40992). [TensorRT-LLM][INFO] Using 9061466112 bytes for LoRA host cache [TensorRT-LLM][INFO] Using 9061466112 bytes for LoRA device cache [TensorRT-LLM][INFO] Max LoRA size is 650121216 [TensorRT-LLM][INFO] LoRA host Cache can hold 7 max sized LoRAs [TensorRT-LLM][INFO] LoRA device Cache can hold 7 max sized LoRAs 2025-05-28 01:19:59,596 - INFO - flashinfer.jit: Loading JIT ops: norm /usr/local/lib/python3.12/dist-packages/torch/utils/cpp_extension.py:2356: UserWarning: TORCH_CUDA_ARCH_LIST is not set, all archs for visible cards are included for compilation. If this is not desired, please set os.environ['TORCH_CUDA_ARCH_LIST']. warnings.warn( /usr/local/lib/python3.12/dist-packages/torch/utils/cpp_extension.py:2356: UserWarning: TORCH_CUDA_ARCH_LIST is not set, all archs for visible cards are included for compilation. If this is not desired, please set os.environ['TORCH_CUDA_ARCH_LIST']. warnings.warn( 2025-05-28 01:19:59,622 - INFO - flashinfer.jit: Finished loading JIT ops: norm 2025-05-28 01:20:00,385 - INFO - flashinfer.jit: Loading JIT ops: silu_and_mul /usr/local/lib/python3.12/dist-packages/torch/utils/cpp_extension.py:2356: UserWarning: TORCH_CUDA_ARCH_LIST is not set, all archs for visible cards are included for compilation. If this is not desired, please set os.environ['TORCH_CUDA_ARCH_LIST']. warnings.warn( /usr/local/lib/python3.12/dist-packages/torch/utils/cpp_extension.py:2356: UserWarning: TORCH_CUDA_ARCH_LIST is not set, all archs for visible cards are included for compilation. If this is not desired, please set os.environ['TORCH_CUDA_ARCH_LIST']. warnings.warn( 2025-05-28 01:20:00,407 - INFO - flashinfer.jit: Finished loading JIT ops: silu_and_mul [TensorRT-LLM][INFO] Max KV cache pages per sequence: 1281 [window size=40961] [TensorRT-LLM][INFO] Number of tokens per block: 32. [TensorRT-LLM][INFO] [MemUsageChange] Allocated 12.95 GiB for max tokens in paged KV cache (53056). [TensorRT-LLM][INFO] Using 9061466112 bytes for LoRA host cache [TensorRT-LLM][INFO] Using 9061466112 bytes for LoRA device cache [TensorRT-LLM][INFO] Max LoRA size is 650121216 [TensorRT-LLM][INFO] LoRA host Cache can hold 7 max sized LoRAs [TensorRT-LLM][INFO] LoRA device Cache can hold 7 max sized LoRAs The code for calling lora is as follows:

`sampling_params = SamplingParams(max_tokens=2000, add_special_tokens=False) lora_req = LoRARequest( "task-0", 0, hf_lora_dir) lora_request = [lora_req]

outputs = llm.generate(prompts, sampling_params,lora_request=lora_request)

`

Question 2: Currently, qwen3 uses pytorch as its backend. How can I deploy the service with triton

oppolll avatar May 27 '25 11:05 oppolll

Maybe @byshiue.

brb-nv avatar May 29 '25 23:05 brb-nv

@shaharmor98 Can you help to reply these questions?

byshiue avatar May 30 '25 01:05 byshiue

It’s possible that the lora_config wasn’t passed to the LLM. The following code appears to work with the Qwen model.

    hf_lora_dir = '/path/to/your/hf_lora'
    model = '/path/to/your/model'

    # Configure LoRA when initializing LLM
    lora_config = LoraConfig(
        lora_dir=[hf_lora_dir],  # Path(s) to LoRA adapter(s)
        max_lora_rank=64,        # Must match your LoRA rank
        max_loras=1,
        max_cpu_loras=1
    )

    # Initialize LLM WITH lora_config
    llm = LLM(
        model=model,
        lora_config=lora_config
    )

    # Define prompts
    prompts = ["Hello, how are you?", "What is AI?"]

    # Create LoRA request (one per prompt, or same request for all)
    lora_request = LoRARequest("task-0", 0, hf_lora_dir)

    # Generate with LoRA - pass list matching number of prompts
    sampling_params = SamplingParams(max_tokens=200, add_special_tokens=False)
    lora_requests = [lora_request] * len(prompts)  # Same LoRA for all prompts
    outputs = llm.generate(prompts, sampling_params, lora_request=lora_requests)

    # Print results
    for output in outputs:
        print(f"Prompt: {output.prompt}")
        print(f"Output: {output.outputs[0].text}")

Thanks!

karljang avatar Dec 19 '25 07:12 karljang