Views
No views yet
| Benchmark | InternLM3-8B-Instruct | Qwen2.5-7B-Instruct | Llama3.1-8B-Instruct | GPT-4o-mini(closed source) | |
|---|---|---|---|---|---|
| General | CMMLU(0-shot) | 83.1 | 75.8 | 53.9 | 66.0 |
| MMLU(0-shot) | 76.6 | 76.8 | 71.8 | 82.7 | |
| MMLU-Pro(0-shot) | 57.6 | 56.2 | 48.1 | 64.1 | |
| Reasoning | GPQA-Diamond(0-shot) | 37.4 | 33.3 | 24.2 | 42.9 |
| DROP(0-shot) | 83.1 | 80.4 | 81.6 | 85.2 | |
| HellaSwag(10-shot) | 91.2 | 85.3 | 76.7 | 89.5 | |
| KOR-Bench(0-shot) | 56.4 | 44.6 | 47.7 | 58.2 | |
| MATH | MATH-500(0-shot) | 83.0* | 72.4 | 48.4 | 74.0 |
| AIME2024(0-shot) | 20.0* | 16.7 | 6.7 | 13.3 | |
| Coding | LiveCodeBench(2407-2409 Pass@1) | 17.8 | 16.8 | 12.9 | 21.8 |
| HumanEval(Pass@1) | 82.3 | 85.4 | 72.0 | 86.6 | |
| Instrunction | IFEval(Prompt-Strict) | 79.3 | 71.7 | 75.2 | 79.7 |
| Long Context | RULER(4-128K Average) | 87.9 | 81.4 | 88.5 | 90.7 |
| Chat | AlpacaEval 2.0(LC WinRate) | 51.1 | 30.3 | 25.0 | 50.7 |
| WildBench(Raw Score) | 33.1 | 23.3 | 1.5 | 40.3 | |
| MT-Bench-101(Score 1-10) | 8.59 | 8.49 | 8.37 | 8.87 |
transformers >= 4.481import torch
2from transformers import AutoTokenizer, AutoModelForCausalLM
3
4model_dir = "internlm/internlm3-8b-instruct"
5tokenizer = AutoTokenizer.from_pretrained(model_dir, trust_remote_code=True)
6# Set `torch_dtype=torch.float16` to load model in float16, otherwise it will be loaded as float32 and might cause OOM Error.
7model = AutoModelForCausalLM.from_pretrained(model_dir, trust_remote_code=True, torch_dtype=torch.bfloat16).cuda()
8# (Optional) If on low resource devices, you can load model in 4-bit or 8-bit to further save GPU memory via bitsandbytes.
9 # InternLM3 8B in 4bit will cost nearly 8GB GPU memory.
10 # pip install -U bitsandbytes
11 # 8-bit: model = AutoModelForCausalLM.from_pretrained(model_dir, device_map="auto", trust_remote_code=True, load_in_8bit=True)
12 # 4-bit: model = AutoModelForCausalLM.from_pretrained(model_dir, device_map="auto", trust_remote_code=True, load_in_4bit=True)
13model = model.eval()
14
15system_prompt = """You are an AI assistant whose name is InternLM (书生·浦语).
16- InternLM (书生·浦语) is a conversational language model that is developed by Shanghai AI Laboratory (上海人工智能实验室). It is designed to be helpful, honest, and harmless.
17- InternLM (书生·浦语) can understand and communicate fluently in the language chosen by the user such as English and 中文."""
18messages = [
19 {"role": "system", "content": system_prompt},
20 {"role": "user", "content": "Please tell me five scenic spots in Shanghai"},
21 ]
22tokenized_chat = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt").to("cuda")
23
24generated_ids = model.generate(tokenized_chat, max_new_tokens=1024, temperature=1, repetition_penalty=1.005, top_k=40, top_p=0.8)
25
26generated_ids = [
27 output_ids[len(input_ids):] for input_ids, output_ids in zip(tokenized_chat, generated_ids)
28]
29prompt = tokenizer.batch_decode(tokenized_chat)[0]
30print(prompt)
31response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
32print(response)pip install lmdeploy1import lmdeploy
2model_dir = "internlm/internlm3-8b-instruct"
3pipe = lmdeploy.pipeline(model_dir)
4response = pipe("Please tell me five scenic spots in Shanghai")
5print(response)
6lmdeploy serve api_server internlm/internlm3-8b-instruct --model-name internlm3-8b-instruct --server-port 23333 1curl http://localhost:23333/v1/chat/completions \
2 -H "Content-Type: application/json" \
3 -d '{
4 "model": "internlm3-8b-instruct",
5 "messages": [
6 {"role": "user", "content": "Please tell me five scenic spots in Shanghai"}
7 ]
8 }'1# install ollama
2curl -fsSL https://ollama.com/install.sh | sh
3# fetch model
4ollama pull internlm/internlm3-8b-instruct
5# install
6pip install ollama1import ollama
2
3system_prompt = """You are an AI assistant whose name is InternLM (书生·浦语).
4- InternLM (书生·浦语) is a conversational language model that is developed by Shanghai AI Laboratory (上海人工智能实验室). It is designed to be helpful, honest, and harmless.
5- InternLM (书生·浦语) can understand and communicate fluently in the language chosen by the user such as English and 中文."""
6
7messages = [
8 {
9 "role": "system",
10 "content": system_prompt,
11 },
12 {
13 "role": "user",
14 "content": "Please tell me five scenic spots in Shanghai"
15 },
16]
17
18stream = ollama.chat(
19 model='internlm/internlm3-8b-instruct',
20 messages=messages,
21 stream=True,
22)
23
24for chunk in stream:
25 print(chunk['message']['content'], end='', flush=True)pip install vllm --pre --extra-index-url https://wheels.vllm.ai/nightly1from vllm import LLM, SamplingParams
2
3llm = LLM(model="internlm/internlm3-8b-instruct")
4sampling_params = SamplingParams(temperature=1, repetition_penalty=1.005, top_k=40, top_p=0.8)
5
6system_prompt = """You are an AI assistant whose name is InternLM (书生·浦语).
7- InternLM (书生·浦语) is a conversational language model that is developed by Shanghai AI Laboratory (上海人工智能实验室). It is designed to be helpful, honest, and harmless.
8- InternLM (书生·浦语) can understand and communicate fluently in the language chosen by the user such as English and 中文."""
9
10prompts = [
11 {
12 "role": "system",
13 "content": system_prompt,
14 },
15 {
16 "role": "user",
17 "content": "Please tell me five scenic spots in Shanghai"
18 },
19]
20outputs = llm.chat(prompts,
21 sampling_params=sampling_params,
22 use_tqdm=False)
23print(outputs)
1thinking_system_prompt = """You are an expert mathematician with extensive experience in mathematical competitions. You approach problems through systematic thinking and rigorous reasoning. When solving problems, follow these thought processes:
2## Deep Understanding
3Take time to fully comprehend the problem before attempting a solution. Consider:
4- What is the real question being asked?
5- What are the given conditions and what do they tell us?
6- Are there any special restrictions or assumptions?
7- Which information is crucial and which is supplementary?
8## Multi-angle Analysis
9Before solving, conduct thorough analysis:
10- What mathematical concepts and properties are involved?
11- Can you recall similar classic problems or solution methods?
12- Would diagrams or tables help visualize the problem?
13- Are there special cases that need separate consideration?
14## Systematic Thinking
15Plan your solution path:
16- Propose multiple possible approaches
17- Analyze the feasibility and merits of each method
18- Choose the most appropriate method and explain why
19- Break complex problems into smaller, manageable steps
20## Rigorous Proof
21During the solution process:
22- Provide solid justification for each step
23- Include detailed proofs for key conclusions
24- Pay attention to logical connections
25- Be vigilant about potential oversights
26## Repeated Verification
27After completing your solution:
28- Verify your results satisfy all conditions
29- Check for overlooked special cases
30- Consider if the solution can be optimized or simplified
31- Review your reasoning process
32Remember:
331. Take time to think thoroughly rather than rushing to an answer
342. Rigorously prove each key conclusion
353. Keep an open mind and try different approaches
364. Summarize valuable problem-solving methods
375. Maintain healthy skepticism and verify multiple times
38Your response should reflect deep mathematical understanding and precise logical thinking, making your solution path and reasoning clear to others.
39When you're ready, present your complete solution with:
40- Clear problem understanding
41- Detailed solution process
42- Key insights
43- Thorough verification
44Focus on clear, logical progression of ideas and thorough explanation of your mathematical reasoning. Provide answers in the same language as the user asking the question, repeat the final answer using a '\\boxed{}' without any units, you have [[8192]] tokens to complete the answer.
45"""1import torch
2from transformers import AutoTokenizer, AutoModelForCausalLM
3
4model_dir = "internlm/internlm3-8b-instruct"
5tokenizer = AutoTokenizer.from_pretrained(model_dir, trust_remote_code=True)
6# Set `torch_dtype=torch.float16` to load model in float16, otherwise it will be loaded as float32 and might cause OOM Error.
7model = AutoModelForCausalLM.from_pretrained(model_dir, trust_remote_code=True, torch_dtype=torch.bfloat16).cuda()
8# (Optional) If on low resource devices, you can load model in 4-bit or 8-bit to further save GPU memory via bitsandbytes.
9 # InternLM3 8B in 4bit will cost nearly 8GB GPU memory.
10 # pip install -U bitsandbytes
11 # 8-bit: model = AutoModelForCausalLM.from_pretrained(model_dir, device_map="auto", trust_remote_code=True, load_in_8bit=True)
12 # 4-bit: model = AutoModelForCausalLM.from_pretrained(model_dir, device_map="auto", trust_remote_code=True, load_in_4bit=True)
13model = model.eval()
14
15messages = [
16 {"role": "system", "content": thinking_system_prompt},
17 {"role": "user", "content": "Given the function\(f(x)=\mathrm{e}^{x}-ax - a^{3}\),\n(1) When \(a = 1\), find the equation of the tangent line to the curve \(y = f(x)\) at the point \((1,f(1))\).\n(2) If \(f(x)\) has a local minimum and the minimum value is less than \(0\), determine the range of values for \(a\)."},
18 ]
19tokenized_chat = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt").to("cuda")
20
21generated_ids = model.generate(tokenized_chat, max_new_tokens=8192)
22
23generated_ids = [
24 output_ids[len(input_ids):] for input_ids, output_ids in zip(tokenized_chat, generated_ids)
25]
26prompt = tokenizer.batch_decode(tokenized_chat)[0]
27print(prompt)
28response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
29print(response)pip install lmdeploy1from lmdeploy import pipeline, GenerationConfig, ChatTemplateConfig
2model_dir = "internlm/internlm3-8b-instruct"
3chat_template_config = ChatTemplateConfig(model_name='internlm3')
4pipe = pipeline(model_dir, chat_template_config=chat_template_config)
5
6messages = [
7 {"role": "system", "content": thinking_system_prompt},
8 {"role": "user", "content": "Given the function\(f(x)=\mathrm{e}^{x}-ax - a^{3}\),\n(1) When \(a = 1\), find the equation of the tangent line to the curve \(y = f(x)\) at the point \((1,f(1))\).\n(2) If \(f(x)\) has a local minimum and the minimum value is less than \(0\), determine the range of values for \(a\)."},
9]
10
11response = pipe(messages, gen_config=GenerationConfig(max_new_tokens=2048))
12print(response)1# install ollama
2curl -fsSL https://ollama.com/install.sh | sh
3# fetch model
4ollama pull internlm/internlm3-8b-instruct
5# install
6pip install ollama1import ollama
2
3messages = [
4 {
5 "role": "system",
6 "content": thinking_system_prompt,
7 },
8 {
9 "role": "user",
10 "content": "Given the function\(f(x)=\mathrm{e}^{x}-ax - a^{3}\),\n(1) When \(a = 1\), find the equation of the tangent line to the curve \(y = f(x)\) at the point \((1,f(1))\).\n(2) If \(f(x)\) has a local minimum and the minimum value is less than \(0\), determine the range of values for \(a\)."
11 },
12]
13
14stream = ollama.chat(
15 model='internlm/internlm3-8b-instruct',
16 messages=messages,
17 stream=True,
18)
19
20for chunk in stream:
21 print(chunk['message']['content'], end='', flush=True)pip install vllm --pre --extra-index-url https://wheels.vllm.ai/nightly1from vllm import LLM, SamplingParams
2
3llm = LLM(model="internlm/internlm3-8b-instruct")
4sampling_params = SamplingParams(temperature=1, repetition_penalty=1.005, top_k=40, top_p=0.8, max_tokens=8192)
5
6prompts = [
7 {
8 "role": "system",
9 "content": thinking_system_prompt,
10 },
11 {
12 "role": "user",
13 "content": "Given the function\(f(x)=\mathrm{e}^{x}-ax - a^{3}\),\n(1) When \(a = 1\), find the equation of the tangent line to the curve \(y = f(x)\) at the point \((1,f(1))\).\n(2) If \(f(x)\) has a local minimum and the minimum value is less than \(0\), determine the range of values for \(a\)."
14 },
15]
16outputs = llm.chat(prompts,
17 sampling_params=sampling_params,
18 use_tqdm=False)
19print(outputs)@misc{cai2024internlm2,
title={InternLM2 Technical Report},
author={Zheng Cai and Maosong Cao and Haojiong Chen and Kai Chen and Keyu Chen and Xin Chen and Xun Chen and Zehui Chen and Zhi Chen and Pei Chu and Xiaoyi Dong and Haodong Duan and Qi Fan and Zhaoye Fei and Yang Gao and Jiaye Ge and Chenya Gu and Yuzhe Gu and Tao Gui and Aijia Guo and Qipeng Guo and Conghui He and Yingfan Hu and Ting Huang and Tao Jiang and Penglong Jiao and Zhenjiang Jin and Zhikai Lei and Jiaxing Li and Jingwen Li and Linyang Li and Shuaibin Li and Wei Li and Yining Li and Hongwei Liu and Jiangning Liu and Jiawei Hong and Kaiwen Liu and Kuikun Liu and Xiaoran Liu and Chengqi Lv and Haijun Lv and Kai Lv and Li Ma and Runyuan Ma and Zerun Ma and Wenchang Ning and Linke Ouyang and Jiantao Qiu and Yuan Qu and Fukai Shang and Yunfan Shao and Demin Song and Zifan Song and Zhihao Sui and Peng Sun and Yu Sun and Huanze Tang and Bin Wang and Guoteng Wang and Jiaqi Wang and Jiayu Wang and Rui Wang and Yudong Wang and Ziyi Wang and Xingjian Wei and Qizhen Weng and Fan Wu and Yingtong Xiong and Chao Xu and Ruiliang Xu and Hang Yan and Yirong Yan and Xiaogui Yang and Haochen Ye and Huaiyuan Ying and Jia Yu and Jing Yu and Yuhang Zang and Chuyu Zhang and Li Zhang and Pan Zhang and Peng Zhang and Ruijie Zhang and Shuo Zhang and Songyang Zhang and Wenjian Zhang and Wenwei Zhang and Xingcheng Zhang and Xinyue Zhang and Hui Zhao and Qian Zhao and Xiaomeng Zhao and Fengzhe Zhou and Zaida Zhou and Jingming Zhuo and Yicheng Zou and Xipeng Qiu and Yu Qiao and Dahua Lin},
year={2024},
eprint={2403.17297},
archivePrefix={arXiv},
primaryClass={cs.CL}
}| 评测集\模型 | InternLM3-8B-Instruct | Qwen2.5-7B-Instruct | Llama3.1-8B-Instruct | GPT-4o-mini(闭源) | |
|---|---|---|---|---|---|
| General | CMMLU(0-shot) | 83.1 | 75.8 | 53.9 | 66.0 |
| MMLU(0-shot) | 76.6 | 76.8 | 71.8 | 82.7 | |
| MMLU-Pro(0-shot) | 57.6 | 56.2 | 48.1 | 64.1 | |
| Reasoning | GPQA-Diamond(0-shot) | 37.4 | 33.3 | 24.2 | 42.9 |
| DROP(0-shot) | 83.1 | 80.4 | 81.6 | 85.2 | |
| HellaSwag(10-shot) | 91.2 | 85.3 | 76.7 | 89.5 | |
| KOR-Bench(0-shot) | 56.4 | 44.6 | 47.7 | 58.2 | |
| MATH | MATH-500(0-shot) | 83.0* | 72.4 | 48.4 | 74.0 |
| AIME2024(0-shot) | 20.0* | 16.7 | 6.7 | 13.3 | |
| Coding | LiveCodeBench(2407-2409 Pass@1) | 17.8 | 16.8 | 12.9 | 21.8 |
| HumanEval(Pass@1) | 82.3 | 85.4 | 72.0 | 86.6 | |
| Instrunction | IFEval(Prompt-Strict) | 79.3 | 71.7 | 75.2 | 79.7 |
| LongContext | RULER(4-128K Average) | 87.9 | 81.4 | 88.5 | 90.7 |
| Chat | AlpacaEval 2.0(LC WinRate) | 51.1 | 30.3 | 25.0 | 50.7 |
| WildBench(Raw Score) | 33.1 | 23.3 | 1.5 | 40.3 | |
| MT-Bench-101(Score 1-10) | 8.59 | 8.49 | 8.37 | 8.87 |
*代表使用深度思考模式进行评测),具体测试细节可参见 OpenCompass 中提供的配置文件。transformers >= 4.481import torch
2from transformers import AutoTokenizer, AutoModelForCausalLM
3
4model_dir = "internlm/internlm3-8b-instruct"
5tokenizer = AutoTokenizer.from_pretrained(model_dir, trust_remote_code=True)
6# Set `torch_dtype=torch.float16` to load model in float16, otherwise it will be loaded as float32 and might cause OOM Error.
7model = AutoModelForCausalLM.from_pretrained(model_dir, trust_remote_code=True, torch_dtype=torch.bfloat16).cuda()
8# (Optional) If on low resource devices, you can load model in 4-bit or 8-bit to further save GPU memory via bitsandbytes.
9 # InternLM3 8B in 4bit will cost nearly 8GB GPU memory.
10 # pip install -U bitsandbytes
11 # 8-bit: model = AutoModelForCausalLM.from_pretrained(model_dir, device_map="auto", trust_remote_code=True, load_in_8bit=True)
12 # 4-bit: model = AutoModelForCausalLM.from_pretrained(model_dir, device_map="auto", trust_remote_code=True, load_in_4bit=True)
13model = model.eval()
14
15system_prompt = """You are an AI assistant whose name is InternLM (书生·浦语).
16- InternLM (书生·浦语) is a conversational language model that is developed by Shanghai AI Laboratory (上海人工智能实验室). It is designed to be helpful, honest, and harmless.
17- InternLM (书生·浦语) can understand and communicate fluently in the language chosen by the user such as English and 中文."""
18messages = [
19 {"role": "system", "content": system_prompt},
20 {"role": "user", "content": "Please tell me five scenic spots in Shanghai"},
21 ]
22tokenized_chat = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt").to("cuda")
23
24generated_ids = model.generate(tokenized_chat, max_new_tokens=1024, temperature=1, repetition_penalty=1.005, top_k=40, top_p=0.8)
25
26generated_ids = [
27 output_ids[len(input_ids):] for input_ids, output_ids in zip(tokenized_chat, generated_ids)
28]
29prompt = tokenizer.batch_decode(tokenized_chat)[0]
30print(prompt)
31response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
32print(response)pip install lmdeploy1import lmdeploy
2model_dir = "internlm/internlm3-8b-instruct"
3pipe = lmdeploy.pipeline(model_dir)
4response = pipe(["Please tell me five scenic spots in Shanghai"])
5print(response)
6lmdeploy serve api_server internlm/internlm3-8b-instruct --model-name internlm3-8b-instruct --server-port 23333 1curl http://localhost:23333/v1/chat/completions \
2 -H "Content-Type: application/json" \
3 -d '{
4 "model": "internlm3-8b-instruct",
5 "messages": [
6 {"role": "user", "content": "介绍一下深度学习。"}
7 ]
8 }'1# install ollama
2curl -fsSL https://ollama.com/install.sh | sh
3# fetch 模型
4ollama pull internlm/internlm3-8b-instruct
5# install python库
6pip install ollama1import ollama
2
3system_prompt = """You are an AI assistant whose name is InternLM (书生·浦语).
4- InternLM (书生·浦语) is a conversational language model that is developed by Shanghai AI Laboratory (上海人工智能实验室). It is designed to be helpful, honest, and harmless.
5- InternLM (书生·浦语) can understand and communicate fluently in the language chosen by the user such as English and 中文."""
6
7messages = [
8 {
9 "role": "system",
10 "content": system_prompt,
11 },
12 {
13 "role": "user",
14 "content": "Please tell me five scenic spots in Shanghai"
15 },
16]
17
18stream = ollama.chat(
19 model='internlm/internlm3-8b-instruct',
20 messages=messages,
21 stream=True,
22)
23
24for chunk in stream:
25 print(chunk['message']['content'], end='', flush=True)pip install vllm --pre --extra-index-url https://wheels.vllm.ai/nightly1from vllm import LLM, SamplingParams
2
3llm = LLM(model="internlm/internlm3-8b-instruct")
4sampling_params = SamplingParams(temperature=1, repetition_penalty=1.005, top_k=40, top_p=0.8)
5
6system_prompt = """You are an AI assistant whose name is InternLM (书生·浦语).
7- InternLM (书生·浦语) is a conversational language model that is developed by Shanghai AI Laboratory (上海人工智能实验室). It is designed to be helpful, honest, and harmless.
8- InternLM (书生·浦语) can understand and communicate fluently in the language chosen by the user such as English and 中文."""
9
10prompts = [
11 {
12 "role": "system",
13 "content": system_prompt,
14 },
15 {
16 "role": "user",
17 "content": "Please tell me five scenic spots in Shanghai"
18 },
19]
20outputs = llm.chat(prompts,
21 sampling_params=sampling_params,
22 use_tqdm=False)
23print(outputs)
1thinking_system_prompt = """You are an expert mathematician with extensive experience in mathematical competitions. You approach problems through systematic thinking and rigorous reasoning. When solving problems, follow these thought processes:
2## Deep Understanding
3Take time to fully comprehend the problem before attempting a solution. Consider:
4- What is the real question being asked?
5- What are the given conditions and what do they tell us?
6- Are there any special restrictions or assumptions?
7- Which information is crucial and which is supplementary?
8## Multi-angle Analysis
9Before solving, conduct thorough analysis:
10- What mathematical concepts and properties are involved?
11- Can you recall similar classic problems or solution methods?
12- Would diagrams or tables help visualize the problem?
13- Are there special cases that need separate consideration?
14## Systematic Thinking
15Plan your solution path:
16- Propose multiple possible approaches
17- Analyze the feasibility and merits of each method
18- Choose the most appropriate method and explain why
19- Break complex problems into smaller, manageable steps
20## Rigorous Proof
21During the solution process:
22- Provide solid justification for each step
23- Include detailed proofs for key conclusions
24- Pay attention to logical connections
25- Be vigilant about potential oversights
26## Repeated Verification
27After completing your solution:
28- Verify your results satisfy all conditions
29- Check for overlooked special cases
30- Consider if the solution can be optimized or simplified
31- Review your reasoning process
32Remember:
331. Take time to think thoroughly rather than rushing to an answer
342. Rigorously prove each key conclusion
353. Keep an open mind and try different approaches
364. Summarize valuable problem-solving methods
375. Maintain healthy skepticism and verify multiple times
38Your response should reflect deep mathematical understanding and precise logical thinking, making your solution path and reasoning clear to others.
39When you're ready, present your complete solution with:
40- Clear problem understanding
41- Detailed solution process
42- Key insights
43- Thorough verification
44Focus on clear, logical progression of ideas and thorough explanation of your mathematical reasoning. Provide answers in the same language as the user asking the question, repeat the final answer using a '\\boxed{}' without any units, you have [[8192]] tokens to complete the answer.
45"""1import torch
2from transformers import AutoTokenizer, AutoModelForCausalLM
3
4model_dir = "internlm/internlm3-8b-instruct"
5tokenizer = AutoTokenizer.from_pretrained(model_dir, trust_remote_code=True)
6# Set `torch_dtype=torch.float16` to load model in float16, otherwise it will be loaded as float32 and might cause OOM Error.
7model = AutoModelForCausalLM.from_pretrained(model_dir, trust_remote_code=True, torch_dtype=torch.bfloat16).cuda()
8# (Optional) If on low resource devices, you can load model in 4-bit or 8-bit to further save GPU memory via bitsandbytes.
9 # InternLM3 8B in 4bit will cost nearly 8GB GPU memory.
10 # pip install -U bitsandbytes
11 # 8-bit: model = AutoModelForCausalLM.from_pretrained(model_dir, device_map="auto", trust_remote_code=True, load_in_8bit=True)
12 # 4-bit: model = AutoModelForCausalLM.from_pretrained(model_dir, device_map="auto", trust_remote_code=True, load_in_4bit=True)
13model = model.eval()
14
15messages = [
16 {"role": "system", "content": thinking_system_prompt},
17 {"role": "user", "content": "已知函数\(f(x)=\mathrm{e}^{x}-ax - a^{3}\)。\n(1)当\(a = 1\)时,求曲线\(y = f(x)\)在点\((1,f(1))\)处的切线方程;\n(2)若\(f(x)\)有极小值,且极小值小于\(0\),求\(a\)的取值范围。"},
18 ]
19tokenized_chat = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt").to("cuda")
20
21generated_ids = model.generate(tokenized_chat, max_new_tokens=8192)
22
23generated_ids = [
24 output_ids[len(input_ids):] for input_ids, output_ids in zip(tokenized_chat, generated_ids)
25]
26prompt = tokenizer.batch_decode(tokenized_chat)[0]
27print(prompt)
28response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
29print(response)pip install lmdeploy1from lmdeploy import pipeline, GenerationConfig, ChatTemplateConfig
2model_dir = "internlm/internlm3-8b-instruct"
3chat_template_config = ChatTemplateConfig(model_name='internlm3')
4pipe = pipeline(model_dir, chat_template_config=chat_template_config)
5
6messages = [
7 {"role": "system", "content": thinking_system_prompt},
8 {"role": "user", "content": "已知函数\(f(x)=\mathrm{e}^{x}-ax - a^{3}\)。\n(1)当\(a = 1\)时,求曲线\(y = f(x)\)在点\((1,f(1))\)处的切线方程;\n(2)若\(f(x)\)有极小值,且极小值小于\(0\),求\(a\)的取值范围。"},
9]
10
11response = pipe(messages, gen_config=GenerationConfig(max_new_tokens=2048))
12print(response)1# install ollama
2curl -fsSL https://ollama.com/install.sh | sh
3# fetch 模型
4ollama pull internlm/internlm3-8b-instruct
5# install python库
6pip install ollama1import ollama
2
3messages = [
4 {
5 "role": "system",
6 "content": thinking_system_prompt,
7 },
8 {
9 "role": "user",
10 "content": "Given the function\(f(x)=\mathrm{e}^{x}-ax - a^{3}\),\n(1) When \(a = 1\), find the equation of the tangent line to the curve \(y = f(x)\) at the point \((1,f(1))\).\n(2) If \(f(x)\) has a local minimum and the minimum value is less than \(0\), determine the range of values for \(a\)."
11 },
12]
13
14stream = ollama.chat(
15 model='internlm/internlm3-8b-instruct',
16 messages=messages,
17 stream=True,
18)
19
20for chunk in stream:
21 print(chunk['message']['content'], end='', flush=True)pip install vllm --pre --extra-index-url https://wheels.vllm.ai/nightly1from vllm import LLM, SamplingParams
2
3llm = LLM(model="internlm/internlm3-8b-instruct")
4sampling_params = SamplingParams(temperature=1, repetition_penalty=1.005, top_k=40, top_p=0.8, max_tokens=8192)
5
6prompts = [
7 {
8 "role": "system",
9 "content": thinking_system_prompt,
10 },
11 {
12 "role": "user",
13 "content": "已知函数\(f(x)=\mathrm{e}^{x}-ax - a^{3}\)。\n(1)当\(a = 1\)时,求曲线\(y = f(x)\)在点\((1,f(1))\)处的切线方程;\n(2)若\(f(x)\)有极小值,且极小值小于\(0\),求\(a\)的取值范围。"
14 },
15]
16outputs = llm.chat(prompts,
17 sampling_params=sampling_params,
18 use_tqdm=False)
19print(outputs)@misc{cai2024internlm2,
title={InternLM2 Technical Report},
author={Zheng Cai and Maosong Cao and Haojiong Chen and Kai Chen and Keyu Chen and Xin Chen and Xun Chen and Zehui Chen and Zhi Chen and Pei Chu and Xiaoyi Dong and Haodong Duan and Qi Fan and Zhaoye Fei and Yang Gao and Jiaye Ge and Chenya Gu and Yuzhe Gu and Tao Gui and Aijia Guo and Qipeng Guo and Conghui He and Yingfan Hu and Ting Huang and Tao Jiang and Penglong Jiao and Zhenjiang Jin and Zhikai Lei and Jiaxing Li and Jingwen Li and Linyang Li and Shuaibin Li and Wei Li and Yining Li and Hongwei Liu and Jiangning Liu and Jiawei Hong and Kaiwen Liu and Kuikun Liu and Xiaoran Liu and Chengqi Lv and Haijun Lv and Kai Lv and Li Ma and Runyuan Ma and Zerun Ma and Wenchang Ning and Linke Ouyang and Jiantao Qiu and Yuan Qu and Fukai Shang and Yunfan Shao and Demin Song and Zifan Song and Zhihao Sui and Peng Sun and Yu Sun and Huanze Tang and Bin Wang and Guoteng Wang and Jiaqi Wang and Jiayu Wang and Rui Wang and Yudong Wang and Ziyi Wang and Xingjian Wei and Qizhen Weng and Fan Wu and Yingtong Xiong and Chao Xu and Ruiliang Xu and Hang Yan and Yirong Yan and Xiaogui Yang and Haochen Ye and Huaiyuan Ying and Jia Yu and Jing Yu and Yuhang Zang and Chuyu Zhang and Li Zhang and Pan Zhang and Peng Zhang and Ruijie Zhang and Shuo Zhang and Songyang Zhang and Wenjian Zhang and Wenwei Zhang and Xingcheng Zhang and Xinyue Zhang and Hui Zhao and Qian Zhao and Xiaomeng Zhao and Fengzhe Zhou and Zaida Zhou and Jingming Zhuo and Yicheng Zou and Xipeng Qiu and Yu Qiao and Dahua Lin},
year={2024},
eprint={2403.17297},
archivePrefix={arXiv},
primaryClass={cs.CL}
}