Instructions to use Qwen/CodeQwen1.5-7B-Chat with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Qwen/CodeQwen1.5-7B-Chat with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Qwen/CodeQwen1.5-7B-Chat") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Qwen/CodeQwen1.5-7B-Chat") model = AutoModelForCausalLM.from_pretrained("Qwen/CodeQwen1.5-7B-Chat") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use Qwen/CodeQwen1.5-7B-Chat with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Qwen/CodeQwen1.5-7B-Chat" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Qwen/CodeQwen1.5-7B-Chat", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Qwen/CodeQwen1.5-7B-Chat
- SGLang
How to use Qwen/CodeQwen1.5-7B-Chat with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "Qwen/CodeQwen1.5-7B-Chat" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Qwen/CodeQwen1.5-7B-Chat", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "Qwen/CodeQwen1.5-7B-Chat" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Qwen/CodeQwen1.5-7B-Chat", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use Qwen/CodeQwen1.5-7B-Chat with Docker Model Runner:
docker model run hf.co/Qwen/CodeQwen1.5-7B-Chat
This model is Awesome
You can say what you want, but among all the most used models, I haven't yet found one that is as effective. The Qwen1.5-7B-Chat works well with bitsandbytes (Q4 and Q8) and still maintains incredible attention. I tested several models in my projects, but the Qwen1.5-7B-Chat is unbeatable. The best feature of all is that it understands the user's language on the first interaction, something that other latest generation models only do through requests. Congratulations and greetings to the Qwen development team. I hope this team continues to develop this increasingly better and open-source model.
To contribute, here is a code to facilitate the use of different models, including Qwen:
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
class LLMQ4:
# Load 6.188 GB
def init(self, repo_id):
# Definindo a configuração para evitar fragmentação
# os.environ['PYTORCH_CUDA_ALLOC_CONF'] = 'expandable_segments:True'
# Model name
model_name = repo_id
self.device = "cuda" if torch.cuda.is_available() else "cpu"
self.tokenizer, self.model = self.initialize_model(model_name)
def initialize_model(self, model_name):
bnb_config = BitsAndBytesConfig(
load_in_4bit=True, bnb_4bit_use_double_quant=True, bnb_4bit_quant_type="nf4", bnb_4bit_compute_dtype=torch.bfloat16
)
# Tokenizer initialization
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name, device_map=self.device, torch_dtype=torch.bfloat16, quantization_config=bnb_config)
return tokenizer, model
def prompt(self, context):
# CONTEXT DEVE TER CONFIGURACAO POR ROLE
text = self.tokenizer.apply_chat_template(
context,
tokenize=False,
add_generation_prompt=True
)
model_inputs = self.tokenizer([text], return_tensors="pt").to(self.device)
generated_ids = self.model.generate(
model_inputs.input_ids,
attention_mask=model_inputs['attention_mask'],
max_new_tokens=38000,
do_sample=True,
temperature=0.6,
top_p=0.9,
repetition_penalty=1.1,
eos_token_id=[
self.tokenizer.eos_token_id,
],
)
generated_ids = [
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
]
response = self.tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
return response
Usage:
llm = LLMQ4('Qwen/Qwen1.5-7B-Chat')
chat_history=[
# Personality SystemPrompts
{"role": "system", "content": "Your name is Jarvis."},
{"role": "user", "content": "What your name?"},
]
response = llm.prompt(chat_history)
chat_history.append({"role": "assistant", "content": response})
chat_history.append({"role": "user", "content": "Do a serach on the internet about..."})
response = llm.prompt(chat_history)
...
thanks for your appreciation. yeah we are gonna to release new stuff, way better than 1.5, for sure
thanks for your appreciation. yeah we are gonna to release new stuff, way better than 1.5, for sure
really excited about that, any idea when (a month or more)?
Update: The new Qwen2 is awesome!
Update: The new Qwen2 is awesome!
7B available?
Update: The new Qwen2 is awesome!