����λ�ã���ҳ > �����̳� > �̳� > LLM ��ģ��ѧϰ��֪�ػ�ϵ��(ʮ��)��VLLM���ܷ�Ծ����ʵ�������������ٵ���Ч�����ȫ��λ�Ż�[�������ݣ�XInference/FastChat�ȿ��]
LLM ��ģ��ѧϰ��֪�ػ�ϵ��(ʮ��)��VLLM���ܷ�Ծ����ʵ�������������ٵ���Ч�����ȫ��λ�Ż�[�������ݣ�XInference/FastChat�ȿ��]
ѵ�����ģ�ͻ������������߲���������ʹ��ģ��������������Ĺ��̣������ǽ�ģ�ͷ������㶨���еĻ����������Ĺ��̡�һ����˵��LLM����������ֱ��ʹ��PyTorch���롢ʹ�� VLLM / XInference / FastChat �ȿ�ܣ�Ҳ����ʹ�� llama.cpp / chatglm.cpp / qwen.cpp ��c++������ܡ�
do_sample���������͡��Ƿ�ʹ�����������ʽ�����������������ΪFalse����ʹ��beam_search��ʽ
temperature�����ڵ�����ĸ���������ʽΪ��
$$
q_i=\frac{\exp(z_i/T)}{\sum_{j}\exp(z_j/T)}\
$$
�ӹ�ʽ���Կ��������TȡֵΪ0����Ч������argmax����ʱ��������û������ԣ�ȡֵΪ������ʱ�ӽ���ȡƽ����һ��temperatureȡֵ����[0, 1]֮�䡣ȡֵԽ�����Ч��Խ�����
������ʴ�ֻ����ȷ���Դ𰸣���Tֵ����Ϊ0����֮����Ϊ����0��
top_k������0������������k���������Ľ���н��в�����kԽ�������Խǿ��ԽСȷ����Խǿ��һ������Ϊ20~100֮�䡣
top_p������0�ĸ�������ʹ���б����ǵĽ���ĸ��ʺʹ���pֵ��pֵԽ�������Խǿ��ԽСȷ����Խǿ��һ������0.7~0.95֮�䡣
repetition_penalty�� ���ڵ���1.0�ĸ���������γͷ��ظ�token��Ĭ��1.0����û�гͷ���
�������ǽ������Իع�ģ�͵������ǽ��µ�token������������������һ��token�Ĺ��̡���ô��ǰ��token�Ѿ����ɵ��м�������ǿ���ֱ�����õġ�������Attention�ṹ��˵��
$$
\text { Attention }(Q, K, V)=\operatorname{softmax}\left(\frac{Q K^T}{\sqrt{d_k}}\right) V
$$
����ʱ��Q�ǵ�token tensor����K��V���ǰ�����������ʷtoken tensor�ij����У����KV�ǿ���ʹ��ǰ�������м����ģ��ⲿ�ֵĻ������KVCache�����Դ�ռ�÷dz��޴�
��ַ: https://github.com/vllm-project/vllm
vLLM��һ����Դ�Ĵ�ģ���������ٿ�ܣ�ͨ��PagedAttention��Ч�ع���attention�л����������ʵ���˱�HuggingFace Transformers��14-24������������
PagedAttention �� vLLM �ĺ��ļ������������LLM�������ڴ��ƿ�����⡣��ͳ��ע�����㷨���Իع��������У���Ҫ����������Token��ע��������ֵ�����洢��GPU�ڴ��У���������һ��Token����Щ����ļ���ֵ����ͨ������ΪKV���档
VLLM֧�־������LLMģ�͵��������١���ʹ�����µķ���������������ٶȣ�
Continuous batching
��ʵ�����������У�һ�����ζ�����ӵ������token���ȿ������ܴ�������ɵ�ģ�����token�������Ҳ�ܴ���python���������У���̵����л�ȴ������������ɺ�һ�����أ�����ζ�ű������Դ�������token��GPU�����ڶ�������в������˷ѡ�continous batching�ķ�ʽ������ÿ����������������������������һ�����ӵ�token��������Ч����������
PagedAttention
ֵ��ע����ǣ�VLLM��Ĭ�Ͻ��Կ���ȫ���Դ�Ԥ����������߻����С�������ٶȣ��û�����ͨ������
gpu_memory_utilization
���ƻ����С��
���Ȱ�װVLLM��
pip install vllm
import os
os.environ['VLLM_USE_MODELSCOPE'] = 'True'
from vllm import LLM, SamplingParams
prompts = [
"Hello, my name is",
"The president of the United States is",
"The capital of France is",
"The future of AI is",
]
sampling_params = SamplingParams(temperature=0.8, top_p=0.95)
llm = LLM(model="qwen/Qwen-1_8B", trust_remote_code=True)
outputs = llm.generate(prompts, sampling_params)
#Print the outputs.
for output in outputs:
prompt = output.prompt
generated_text = output.outputs[0].text
print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")
ע�⣬��ֹ�����ĵ���д��ɣ�VLLM��Chatģ�͵�����֧�֣�ģ��ͽ��������������⣬��ʵ�ʽ��в���ʱ�뿼��ʹ��SWIFT����FastChat��
LLM��generate����֧��ֱ������ƴ�Ӻõ�tokens(prompt_token_ids��������ʱ��Ҫ����prompts����)�������ⲿ���԰����Լ���ģ�����ƴ�Ӻ���VLLM��SWIFT����ʹ�������ַ���
�������½������ǽ����� AWQ���� ��VLLMֱ��֧�ִ����������ģ�ͽ���������
from vllm import LLM, SamplingParams
import os
import torch
os.environ['VLLM_USE_MODELSCOPE'] = 'True'
#Sample prompts.
prompts = [
"Hello, my name is",
"The president of the United States is",
"The capital of France is",
"The future of AI is",
]
#Create a sampling params object.
sampling_params = SamplingParams(temperature=0.8, top_p=0.95)
#Create an LLM.
llm = LLM(model="ticoAg/Qwen-1_8B-Chat-Int4-awq", quantization="AWQ", dtype=torch.float16, trust_remote_code=True)
#Generate texts from the prompts. The output is a list of RequestOutput objects
#that contain the prompt, generated text, and other information.
outputs = llm.generate(prompts, sampling_params)
#Print the outputs.
for output in outputs:
prompt = output.prompt
generated_text = output.outputs[0].text
print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")
VLLM�ٷ��ĵ����Բ鿴 ���� ��
��ַ�� https://github.com/modelscope/swift/tree/main
SWIFT��Scalable lightWeight Infrastructure for Fine-Tuning���ǻ���PyTorch�������������伴�õ�ģ��΢����������ܡ������������˸��࿪Դtuners����LoRA��QLoRA��Adapter�ȣ������ں���ModelScope�������е�����tuner ResTuning�������ڴˣ�����ģ̬�Ŀ����߾������ҵ��ʺ��Լ�ģ�͵Ŀ�����ʽ��
SWIFT��tuners��������������Transformer�ṹ��ģ�ͣ�Ҳ�����������ṹ�����ѧϰģ�ͣ�����һ�д��봴����΢��ģ�ͣ�ʵ�ֲ�����Ч���ڴ��Ч��ʱ���Ч��ѵ�����̡�
SWIFT�����޷켯�ɵ�ModelScope��̬ϵͳ�У���ͨ���ݼ���ȡ��ģ�����ء�ģ��ѵ����ģ��������ģ���ϴ������̡����⣬SWIFT��PEFT��ȫ���ݣ� ��ϤPEFT���û�����ʹ��SWIFT�������ModelScope��ģ�ͽ��б�ݵ�ѵ��������
��ΪModelScope�������еĿ�Դ������tuner ResTuning���ü�����cv����ģ̬�������������ϵ����֤����ѵ��Ч��������΢�������൱������£����������Դ��ʡ30%~60%��Ϊcv����ģ̬ģ�͵�ѵ���ṩ���µķ�ʽ����δ����Ӧ����Խ��Խ��ij����ϡ�
��SWIFT�У�����֧����VLLM�����������ֶΡ�
pip install ms-swift[llm] openai
ֻ��Ҫ�������������Ϳ���ʹ��VLLM����������
swift infer --model_id_or_path qwen/Qwen-1_8B-Chat --max_new_tokens 128 --temperature 0.3 --top_p 0.7 --repetition_penalty 1.05 --do_sample true
Ҳ֧���ڲ�����ʹ��VLLM��
swift deploy --model_id_or_path qwen/Qwen-1_8B-Chat --max_new_tokens 128 --temperature 0.3 --top_p 0.7 --repetition_penalty 1.05 --do_sample true
���ã�
from openai import OpenAI
client = OpenAI(
api_key='EMPTY',
base_url='http://localhost:8000/v1',
)
model_type = client.models.list().data[0].id
print(f'model_type: {model_type}')
query = '�ã½ï¿½ï¿½Ê¡ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½?'
messages = [{
'role': 'user',
'content': query
}]
resp = client.chat.completions.create(
model=model_type,
messages=messages,
seed=42)
response = resp.choices[0].message.content
print(f'query: {query}')
print(f'response: {response}')
#��ʽ
messages.append({'role': 'assistant', 'content': response})
query = '����ʲô�óԵ�?'
messages.append({'role': 'user', 'content': query})
stream_resp = client.chat.completions.create(
model=model_type,
messages=messages,
stream=True,
seed=42)
print(f'query: {query}')
print('response: ', end='')
for chunk in stream_resp:
print(chunk.choices[0].delta.content, end='', flush=True)
print()
"""Out[0]
model_type: qwen-7b-chat
query: �ã½ï¿½ï¿½Ê¡ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½?
response: �ã½Ê¡ï¿½ï¿½Ê¡ï¿½ï¿½ï¿½Çºï¿½ï¿½ï¿½ï¿½Ð¡ï¿½
query: ����ʲô�óԵ�?
response: ������������ʳ�������������㡢�����⡢����Ϻ�ʡ��л�ͯ�Ӽ��ȡ����⣬���ݻ���������ɫС�ԣ�������ź�ۡ�����С���������������ȡ�
"""
llama.cpp��ʹ��c++���Ա�д�Ķ�llamaϵ��ģ�ͽ��и�Ч���������������Ŀ�Դ�⡣�ÿ�ʹ����ggml�ײ����������������ʹ��֮ǰ��Ҫ���⽫python��weightsתΪggml��ʽ��gguf��ʽ����ʹ�á���llama.cpp���ƣ����м���ChatGLMģ�͵�chatglm.cpp�ͼ���qwenģ�͵�qwen.cpp��mistral��mistral.cpp��
��װ������
pip install modelscope
git clone --recursive https://github.com/QwenLM/qwen.cpp && cd qwen.cpp
cmake -B build
cmake --build build -j --config Release
����ģ�ͣ�
from modelscope import snapshot_download
print(snapshot_download('qwen/Qwen-1_8B-Chat'))
#/mnt/workspace/.cache/modelscope/qwen/Qwen-1_8B-Chat
��Ôʼģ��ת��Ϊggml֧�ֵĸ�ʽ��
python3 qwen_cpp/convert.py -i /mnt/workspace/.cache/modelscope/qwen/Qwen-1_8B-Chat -t q4_0 -o qwen1_8b-ggml.bin
./build/bin/main -m qwen1_8b-ggml.bin --tiktoken /mnt/workspace/.cache/modelscope/qwen/Qwen-1_8B-Chat/qwen.tiktoken -p ���
#��ã���ʲô�ҿ��԰��������
�����½������ǽ��ܣ�GGML���ʺ���CPU���У�����Ƽ��û���CPU�����л��Ե�����п���cpp�����������
FastChat Github��ַ:
https://github.com/lm-sys/FastChat
FastChat�ܹ���
https://github.com/lm-sys/FastChat/blob/main/docs/server_arch.md
FastChat��һ����Դ�����⣬������ģ�͵ķֲ�ʽ����ʵ�֣����ṩ��OpenAI��ʽ��RESTFul API����һ������ƽ̨������ѵ����������������ڴ�������ģ�͵���������ˡ�
pip3 install "fschat[model_worker,webui]"
python3 -m fastchat.serve.controller
���µ�terminal��������
FASTCHAT_USE_MODELSCOPE=true python3 -m fastchat.serve.model_worker --model-path qwen/Qwen-1_8B-Chat --revision v1.0.0
֮�����µ�terminal�п������н����������:
python3 -m fastchat.serve.gradio_web_server
��ַ�� https://github.com/microsoft/DeepSpeed
��ַ�� https://www.deepspeed.ai/training/
Deepspeed���п�ܽ���
��
https://github.com/wzzzd/LLM_Learning_Note/blob/main/Parallel/deepspeed.md
Deepspeed��΢���Ƴ���һ����Դ�ֲ�ʽ���ߣ��伯���˷ֲ�ʽѵ�����ƶϡ�ѹ���ȸ�Чģ�顣 �ù���ּ����ߴ��ģģ��ѵ����Ч�ʺͿ���չ�ԡ���ͨ�����ּ����ֶ�������ѵ��������ģ�Ͳ��л����ݶ��ۻ�����̬�������š�����ģʽ��Ͼ��ȵȡ�DeepSpeed���ṩ��һЩ�������ߣ���ֲ�ʽѵ���������ڴ��Ż���ģ��ѹ���ȣ��԰��������߸��õع������Ż����ģ���ѧϰѵ�����񡣴��⣬deepspeed����pytorch������ֻ��Ҫ���޸ļ���Ǩ�ơ� DeepSpeed�Ѿ���������ģ���ѧϰ��Ŀ�еõ���Ӧ�ã���������ģ�͡�ͼ����ࡢĿ����ȡ�
DeepSpeed����Microsoft�ṩ�ķֲ�ʽѵ�����ߣ�ּ��֧�ָ����ģ��ģ�ͺ��ṩ������Ż����Ժ͹��ߡ������������ȣ�DeepSpeed֧�ָ����ģ��ģ�ͺ��ṩ������Ż����Ժ͹��ߡ����У���Ҫ��������֧�ָ����ģ��ģ�͡��ṩ�˸�����Ż����Ժ͹��ߣ����� ZeRO �� Offload �ȣ�
���������
���������������ע���ţ�͡ؼ�˹����ܣ����ṩһЩ��ص���Դ���������£���ѻ�ȡ�Ķ���
ʹ��Blender���ɳ���ģ��
�Ķ�ȫ����������ERA5�����ط���
�Ķ�Xpath���������﷨
�Ķ�����ѧϰ�������繹�����£�
�Ķ���ΪMateƷ��ʢ�䣺HarmonyOS NEXT�ӳ�����Ϸ���ܵõ�����ͷ�
�Ķ�ʵ�ֶ��󼯺���DataTable���໥ת��
�Ķ�Ӳ�̵Ļ���֪ʶ��ѡ��ָ��
�Ķ�������й��ƶ��ı�ͼ��ײ�
�Ķ�����NEXTԪ�����������ѿ����ϼ���Ʒ
�Ķ��ᳲ���С������������Ƽ��رշ���
�Ķ������ArcMap�����н���դ��ͼ���ز�������
�Ķ��㷨�����ݽṹ 1 - ģ��
�Ķ���Ѷ�����߿ͷ���Ӫ��ϵͳ����
�Ķ���Ѷ��Ƶҹ��ģʽ���ý̳�
�Ķ����ں���NEXT��Ѫ���Ŵ���������������
�Ķ�5. Spring Cloud OpenFeign ����ʽ WebService �ͻ��˵ij���ϸʹ��
�Ķ�Java����ģʽ����̬�����Ͷ�̬�����ĶԱȷ���
�Ķ�Win11�ʼDZ����Զ�����Ӧ�õ���ɫ����ʾ����
�Ķ�˼�� V1.5.6 ��׿��
��ս�귨 V7.5.0 ��׿��
У��������������׵������� V1.0 ��׿��
��˸֮�� V1.9.7 ��׿��
������Ե����� v1.0.4 ��׿��
������֮ŠV5.2.3 ��׿��
��������������Դ V1.0 ��׿��
���֮Ϣ V1.0 ��׿��
��ħ������������䣩 V1.0 ��׿��
���ں�������ϵ�����������������վ�����������������Ƽ�����
Ƶ�� ����Ƶ��������ר������������׿�������app����
�Ƽ� ��Ô���������°��������ܿ������ز���
���� ����ɫ������������ ���������ս������������
ɨ��ά�����������ֻ��汾��
ɨ��ά����������΢�Ź��ںţ�
��վ�������������������ϴ��������ַ���İ�Ȩ���뷢�ʼ�[email protected]
��ICP��2022002427��-10 �湫��������43070202000427��© 2013~2025 haote.com ������