Views
No views yet
pip install lmdeploy1from lmdeploy import pipeline, GenerationConfig, TurbomindEngineConfig
2
3backend_config = TurbomindEngineConfig(
4 rope_scaling_factor=2.5,
5 session_len=1048576, # 1M context length
6 max_batch_size=1,
7 cache_max_entry_count=0.7,
8 tp=4) # 4xA100-80G.
9pipe = pipeline('internlm/internlm2_5-7b-chat-1m', backend_config=backend_config)
10prompt = 'Use a long prompt to replace this sentence'
11response = pipe(prompt)
12print(response)1import torch
2from transformers import AutoTokenizer, AutoModelForCausalLM
3tokenizer = AutoTokenizer.from_pretrained("internlm/internlm2_5-7b-chat-1m", trust_remote_code=True)
4# Set `torch_dtype=torch.float16` to load model in float16, otherwise it will be loaded as float32 and cause OOM Error.
5model = AutoModelForCausalLM.from_pretrained("internlm/internlm2_5-7b-chat-1m", torch_dtype=torch.float16, trust_remote_code=True).cuda()
6model = model.eval()
7response, history = model.chat(tokenizer, "hello", history=[])
8print(response)
9# Hello! How can I help you today?
10response, history = model.chat(tokenizer, "please provide three suggestions about time management", history=history)
11print(response)stream_chat:1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
3
4model_path = "internlm/internlm2_5-7b-chat-1m"
5model = AutoModelForCausalLM.from_pretrained(model_path, torch_dtype=torch.float16, trust_remote_code=True).cuda()
6tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
7
8model = model.eval()
9length = 0
10for response, history in model.stream_chat(tokenizer, "Hello", history=[]):
11 print(response[length:], flush=True, end="")
12 length = len(response)vLLM>=0.3.2:pip install vllmpython -m vllm.entrypoints.openai.api_server --model internlm/internlm2_5-7b-chat-1m --served-model-name internlm2_5-7b-chat-1m --trust-remote-code--max-model-len or increase --tensor-parallel-size.1curl http://localhost:8000/v1/chat/completions \
2 -H "Content-Type: application/json" \
3 -d '{
4 "model": "internlm2_5-7b-chat-1m",
5 "messages": [
6 {"role": "system", "content": "You are a helpful assistant."},
7 {"role": "user", "content": "Introduce deep learning to me."}
8 ]
9 }'