Alle Open Source, vollständig kommerzialisierte chinesische Version des LLAMA2-Modells und chinesisch-englisch-sft-Datensatzes . Das Eingangsformat folgt streng dem Lama-2-Chat- Format und ist mit allen Optimierungen für das ursprüngliche LLAMA-2-CHAT- Modell kompatibel.


Reden ist billig, zeig dir die Demo.
Modell Download
4 -Bit -Quantisierung
GGML Q4 -Modell:
Wir haben chinesische und englische SFT -Datensätze mit einem Datenvolumen von 10 Millionen verwendet.
from transformers import AutoTokenizer , AutoModelForCausalLM , TextStreamer
model_path = "LinkSoul/Chinese-Llama-2-7b"
tokenizer = AutoTokenizer . from_pretrained ( model_path , use_fast = False )
model = AutoModelForCausalLM . from_pretrained ( model_path ). half (). cuda ()
streamer = TextStreamer ( tokenizer , skip_prompt = True , skip_special_tokens = True )
instruction = """[INST] <<SYS>> n You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature.
If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information. n <</SYS>> n n {} [/INST]"""
prompt = instruction . format ( "用中文回答,When is the best time to visit Beijing, and do you have any suggestions for me?" )
generate_ids = model . generate ( tokenizer ( prompt , return_tensors = 'pt' ). input_ids . cuda (), max_new_tokens = 4096 , streamer = streamer ) Sie können DockerFile im Repository verwenden, um schnell ein grundlegendes Bild zu erstellen, das auf der neuesten Version von nvcr.io/nvidia/pytorch:23.06-py3 basiert, und verwenden Container überall, um chinesische LLAMA2-Modellanwendungen auszuführen.
docker build -t linksoul/chinese-llama2-chat .Verwenden Sie nach dem Erstellen des Bildes den Befehl, um das Bild auszuführen:
docker run --gpus all --ipc=host --ulimit memlock=-1 --ulimit stack=67108864 --rm -it -v ` pwd ` /LinkSoul:/app/LinkSoul -p 7860:7860 linksoul/chinese-llama2-chatMöchten Sie das LLAMA2 -Modell in einer CPU -Umgebung ausführen? Verwenden Sie die folgende Methode.
ggml/convert_to_ggml.py um Conversion -Operationen durchzuführen. Weitere Informationen finden Sie in den CLI -Parametern, die vom Skript unterstützt werden.docker pull soulteary/llama2:converter , um das Bildformat -Conversion -Toolbild des Modells herunterzuladen und die folgenden zwei Befehle im Docker -Container zu verwenden, um den Vorgang abzuschließen (Tutorial, um ein Metaai Llama2 Chinese Big Model zu erstellen, das mit der CPU ausgeführt werden kann): python3 convert.py /app/LinkSoul/Chinese-Llama-2-7b/ --outfile /app/LinkSoul/Chinese-Llama-2-7b-ggml.bin
./quantize /app/LinkSoul/Chinese-Llama-2-7b-ggml.bin /app/LinkSoul/Chinese-Llama-2-7b-ggml-q4.bin q4_0Quantitative Konfigurationsdefinition:
Nachgedruckt aus: https://www.reddit.com/r/localllama/comments/139yt87/notable_diffects_between_q4_2_and_q5_1/
Q4_0 = 32 Zahlen im Stau, 4 Bit pro Gewicht, 1 Skalierungswert bei 32-Bit-Schwimmer (5 Bit pro Wert im Durchschnitt), jedes Gewicht wird durch den quantisierten Wert der gemeinsamen Skala angegeben.
Q4_1 = 32 Zahlen im Stau, 4 Bit pro Gewicht, 1 Skalierungswert und 1 Bias-Wert bei 32-Bit-Schwimmer (6 Bit pro Wert im Durchschnitt), jedes Gewicht wird durch die gemeinsame Skala angegeben * quantisierter Wert + gemeinsame Verzerrung.
q4_2 = gleich wie Q4_0, aber 16 Zahlen im Chunk, 4 Bit pro Gewicht, 1 Skalenwert, der 16-Bit-Schwimmer ist, gleich groß wie Q4_0, aber besser, weil die Stücke kleiner sind.
Q4_3 = bereits tot, aber analog: Q4_1, aber 16 Zahlen in Chunk, 4 Bit pro Gewicht, Skalierungswert, der 16 Bit und Verzerrung ebenfalls 16 Bit, gleiche Größe wie Q4_1, aber besser, weil die Teile kleiner sind.
Q5_0 = 32 Zahlen im Stadel
Q5_1 = 32 Zahlen in einem Stau, 5 Bit pro Gewicht, 1 Skalenwert bei 16 Bit float und 1 Bias -Wert bei 16 Bit, die Größe 6 Bit pro Gewicht.
Q8_0 = gleich wie Q4_0, außer 8 Bit pro Gewicht, 1 Skalierungswert bei 32 Bit, was insgesamt 9 Bit pro Gewicht erzeugt.
Zuerst müssen Sie die zusätzliche Abhängigkeits pip install fastapi uvicorn und dann API.PY im Repository auszuführen:
python api.pyStellen Sie standardmäßig auf dem lokalen Port 8000 bereit und rufen Sie sie über die Post -Methode auf.
curl -X POST " http://127.0.0.1:8000 "
-H ' Content-Type: application/json '
-d ' {"prompt": "你好", "history": []} 'Der erhaltene Rückgabewert ist
{
" response " : " 你好!我是一个人工智能语言模型,可以回答你的问题和进行对话。请问你有什么需要帮助的吗? " ,
" history " :[[ " <<SYS>>nYou are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature.nn If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information.n<</SYS>>nn你好" , " 你好!我是一个人工智能语言模型,可以回答你的问题和进行对话。请问你有什么需要帮助的吗? " ]],
" status " :200,
" time " : " 2023-08-01 09:22:16 "
}DATASET= " LinkSoul/instruction_merge_set "
DATA_CACHE_PATH= " hf_datasets_cache "
MODEL_PATH= " /PATH/TO/TRANSFORMERS/VERSION/LLAMA2 "
output_dir= " ./checkpoints_llama2 "
torchrun --nnodes=1 --node_rank=0 --nproc_per_node=8
--master_port=25003
train.py
--model_name_or_path ${MODEL_PATH}
--data_path ${DATASET}
--data_cache_path ${DATA_CACHE_PATH}
--bf16 True
--output_dir ${output_dir}
--num_train_epochs 1
--per_device_train_batch_size 4
--per_device_eval_batch_size 4
--gradient_accumulation_steps 1
--evaluation_strategy ' no '
--save_strategy ' steps '
--save_steps 1200
--save_total_limit 5
--learning_rate 2e-5
--weight_decay 0.
--warmup_ratio 0.03
--lr_scheduler_type cosine
--logging_steps 1
--fsdp ' full_shard auto_wrap '
--fsdp_transformer_layer_cls_to_wrap ' LlamaDecoderLayer '
--tf32 True
--model_max_length 4096
--gradient_checkpointing TrueApache-2.0-Lizenz
