intel-analytics / ipex-llm

Accelerate local LLM inference and finetuning (LLaMA, Mistral, ChatGLM, Qwen, Mixtral, Gemma, Phi, MiniCPM, Qwen-VL, MiniCPM-V, etc.) on Intel XPU (e.g., local PC with iGPU and NPU, discrete GPU such as Arc, Flex and Max); seamlessly integrate with llama.cpp, Ollama, HuggingFace, LangChain, LlamaIndex, vLLM, GraphRAG, DeepSpeed, Axolotl, etc
Apache License 2.0
6.73k stars 1.27k forks source link

[NPU] dump prefill IR for further C++ solution #12402

Closed rnwang04 closed 2 days ago

rnwang04 commented 1 week ago

Description

1. Why the change?

https://github.com/analytics-zoo/nano/issues/1716#issue-2628191642 To support pure c++ NPU solution, we need to provide a "compile" tool for user to save all needed files (IR / bin / blob).

2. User API changes

Added two params:

model = AutoModelForCausalLM.from_pretrained(model_path,
                                             optimize_model=True,
                                             pipeline=True,
                                             load_in_low_bit=args.load_in_low_bit,
                                             max_context_len=args.max_context_len,
                                             max_prompt_len=args.max_prompt_len,
                                             quantization_group_size=args.quantization_group_size,
                                             torch_dtype=torch.float16,
                                             attn_implementation="eager",
                                             transpose_value_cache=not args.disable_transpose_value_cache,
                                             mixed_precision=True,
                                             trust_remote_code=True,
                                             compile_full_model=True,
                                             save_directory=save_dir)
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
tokenizer.save_pretrained(save_dir)

3. Summary of the change

4. Verify correctness

Only update qwen2 for now, can be extended to other models later.

rnwang04 commented 4 days ago

C++ output verification can be found here: https://github.com/intel-analytics/llm.cpp/pull/655