intel-analytics / ipex-llm

Accelerate local LLM inference and finetuning (LLaMA, Mistral, ChatGLM, Qwen, Baichuan, Mixtral, Gemma, Phi, MiniCPM, 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, GraphRAG, DeepSpeed, vLLM, FastChat, Axolotl, etc.
Apache License 2.0
6.55k stars 1.25k forks source link

Issue while using IPEX-LLM optimized Mixtral model in Langchain agent creation #11442

Open tsantra opened 3 months ago

tsantra commented 3 months ago

Below code works when I am using Mixtral model from Ollama directly. But when I use the IPEX-LLM optimized Mixtral model, the tool does not work. This is an easy tool for testing functionality , which just prints the text file. While Ollama is able to print it, but when I use the IPEX-LLM optimized model, I get a different output (below)

Code:

from langchain.agents import AgentExecutor, create_react_agent from react_template import get_react_prompt_template from ipex_llm.langchain.llms import TransformersLLM from custom_tool import report_generator from langchain_community.llms import Ollama from custom_tool import report_generator

Get the prompt to use - you can modify this!

prompt = get_react_prompt_template()

llm = Ollama(model="mixtral", temperature=0)

llm = TransformersLLM.from_model_id( model_id= , model_kwargs={"temperature": 0, "max_length": 1024, "trust_remote_code": True}, )

llm.model.save_low_bit(low_bit_model_path) del llm

low_bit_llm = TransformersLLM.from_model_id_low_bit( model_id=low_bit_model_path, tokenizer_id= , model_kwargs={"temperature": 0, "max_length": 1024, "trust_remote_code": True} )

tools =[report_generator]

Construct the ReAct agent

agent = create_react_agent(low_bit_llm, tools, prompt)

Create an agent executor by passing in the agent and tools

agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=False, handle_parsing_errors=True)

file_path = "./model_summary.txt" r = agent_executor.invoke({"input": file_path})

Code for tool:

from langchain.agents import tool @tool def report_generator(file_path: str) -> str: """ Reads a text file and prints the content of it.

Args:
    file_path (str): Path to the text file to be read.

Returns:
    str: The status that printing of the content is done.
"""

try:
    # Read the content of the text file
    with open(file_path, 'r') as file:
        content = file.read()
except FileNotFoundError:
    return "Error: The file was not found."
except Exception as e:
    return f"Error: An error occurred while reading the file. Details: {str(e)}"

print ("content is ", content)

return "printing is complete!"

Output

Attached the log file. agent_ipex_log.txt

shane-huang commented 3 months ago

In the attached log, I saw a message "user provided a file path that does not exist or the file is empty" (see details below). Did you specify the correct file path?

Question: ./model_summary.txt Thought: The user wants me to read the content of the text file model_summary.txt. I can use the report_generator tool to do this. Action: report_generator Action Input: ./model_summary.txt ObservationInvalid or incomplete response The user provided a file path that does not exist or the file is empty. I will inform the user about this. Final Answer: The file at ./model_summary.txt does not exist or is empty. Please provide a valid file path.

shane-huang commented 3 months ago

And could you attach the code script and input file and tell us the exact command to execute the script? There're code formatting issues in your question and it's difficult to read your code and reproduce your result.

tsantra commented 3 months ago

@shane-huang agent.zip

attached agent.zip , there are two scripts in the folder. The input file model_summary.txt is inside the folder.

Run command: python agent_ipex_test.py

Also, in the agent_ipex_test.py , please set the hf_model variable to <path where mistralai/Mixtral-8x7B-Instruct-v0.1 from hugginface is saved in your machine>

Also, about the issue "user provided a file path that does not exist or the file is empty" in the log file, yes the path is correct. And Ollama is being able to access the input file in the same path. The problem is , IPEX-LLM optimized model is not able to access it.

Please let me know if you have any questions. Thank you.

shane-huang commented 3 months ago

We will try reproduce your result.

lzivan commented 3 months ago

Hi @tsantra , what environment are you running at? Would you please attach your hardware info, ex. GPU, CPU, RAM below?

tsantra commented 3 months ago

hi @lzivan ,

I am using CPU. Sapphire Rapids.

HW Info: Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Address sizes: 52 bits physical, 57 bits virtual Byte Order: Little Endian CPU(s): 128 On-line CPU(s) list: 0-127 Vendor ID: GenuineIntel Model name: Intel(R) Xeon(R) Gold 6430L CPU family: 6 Model: 143 Thread(s) per core: 2 Core(s) per socket: 32 Socket(s): 2 Stepping: 7 CPU max MHz: 3400.0000 CPU min MHz: 800.0000 BogoMIPS: 3800.00 Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc a rt arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl smx est tm2 ssse3 sdbg fma cx16 xt pr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 cat_l2 cdp_l3 invp cid_single intel_ppin cdp_l2 ssbd mba ibrs ibpb stibp ibrs_enhanced fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb intel_pt avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local splitlock detect avx_vnni avx512_bf16 wbnoinvd dtherm ida arat pln pts hwp hwp_act_window hwp_epp hwp_pkg_req avx512vbmi umip pku ospke waitpkg avx512_vbmi2 gfni vaes vpclmu lqdq avx512_vnni avx512_bitalg tme avx512_vpopcntdq la57 rdpid bus_lock_detect cldemote movdiri movdir64b enqcmd fsrm md_clear serialize tsxldtrk pconfig arch_lbr amx_bf16 avx512_fp16 amx_tile amx_int8 flush_l1d arch_capabilities Caches (sum of all):
L1d: 3 MiB (64 instances) L1i: 2 MiB (64 instances) L2: 128 MiB (64 instances) L3: 120 MiB (2 instances) NUMA:
NUMA node(s): 2 NUMA node0 CPU(s): 0-31,64-95 NUMA node1 CPU(s): 32-63,96-127 Vulnerabilities:
Gather data sampling: Not affected Itlb multihit: Not affected L1tf: Not affected Mds: Not affected Meltdown: Not affected Mmio stale data: Not affected Retbleed: Not affected Spec rstack overflow: Not affected Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl and seccomp Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization Spectre v2: Mitigation; Enhanced IBRS; IBPB conditional; RSB filling; PBRSB-eIBRS SW sequence; BHI BHI_DIS_S Srbds: Not affected Tsx async abort: Not affected

RAM: : 125G

Attached environment info. env.txt

lzivan commented 3 months ago

I see. We have already reproduced the problem, and got a similar log compared to yours. We will get back to you once we got a solution.

tsantra commented 2 months ago

@lzivan Could you please let me know if there is any update? thanks a lot!