Views
No views yet
Meta-Llama-3-8B-Instruct-zh-10k, was fine-tuned from the original Meta-Llama-3-8B-Instruct due to its underperformance in Chinese. Utilizing the LoRa technology within the LLaMA-Factory utilities, this model was adapted to better handle Chinese through three epochs on three corpora: alpaca_zh, alpaca_gpt4_zh, and oaast_sft_zh, amounting to approximately 10,000 examples. This is reflected in the 10k in its name.Meta-Llama-3-8B-Instruct-zh-10k 微调自此。在LLaMA-Factory工具下,利用LoRa 技术,通过alpaca_zh、alpaca_gpt4_zh和oaast_sft_zh三个语料库上、经过三个训练轮次,我们将该模型调整得更好地掌握了中文。三个语料库共计约10,000个样本,这也是其名字中的 10k 的由来。[!NOTE] The complete fine-tuning process took approximately 12 hours. / 完整微调过程花费约12小时。
1# !pip install accelerate
2
3import torch
4from transformers import AutoTokenizer, AutoModelForCausalLM
5
6model_id = "XavierSpycy/Meta-Llama-3-8B-Instruct-zh-10k"
7
8model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.bfloat16, device_map="auto")
9tokenizer = AutoTokenizer.from_pretrained(model_id)
10
11prompt = "你好,你是谁?"
12
13messages = [
14 {"role": "system", "content": "你是一个乐于助人的助手。"},
15 {"role": "user", "content": prompt}]
16
17input_ids = tokenizer.apply_chat_template(
18 messages, add_generation_prompt=True, return_tensors="pt").to(model.device)
19
20terminators = [tokenizer.eos_token_id, tokenizer.convert_tokens_to_ids("<|eot_id|>")]
21
22outputs = model.generate(
23 input_ids,
24 max_new_tokens=256,
25 eos_token_id=terminators,
26 do_sample=True,
27 temperature=0.6,
28 top_p=0.9)
29
30response = outputs[0][input_ids.shape[-1]:]
31
32print(tokenizer.decode(response, skip_special_tokens=True))
33# 我是一个人工智能助手,旨在帮助用户解决问题和完成任务。
34# 我是一个虚拟的人工智能助手,能够通过自然语言处理技术理解用户的需求并为用户提供帮助。1# CMAKE_ARGS="-DLLAMA_BLAS=ON -DLLAMA_BLAS_VENDOR=OpenBLAS # -DLLAMA_CUDA=on" \
2# pip install llama-cpp-python \
3# --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/cu121
4
5# Please download the model weights first. / 请先下载模型权重。
6
7from llama_cpp import Llama
8
9llm = Llama(
10 model_path="/path/to/your/model/Meta-Llama-3-8B-Instruct-zh-10k-GGUF/meta-llama-3-8b-instruct-zh-10k.Q8_0.gguf",
11 n_gpu_layers=-1)
12
13# Alternatively / 或者
14# llm = Llama.from_pretrained(
15# repo_id="XavierSpycy/Meta-Llama-3-8B-Instruct-zh-10k-GGUF",
16# filename="*Q8_0.gguf",
17# verbose=False
18# )
19
20output = llm(
21 "Q: 你好,你是谁?A:", # Prompt
22 max_tokens=256, # Generate up to 32 tokens, set to None to generate up to the end of the context window
23 stop=["Q:", "\n"], # Stop generating just before the model would generate a new question
24 echo=True # Echo the prompt back in the output
25) # Generate a completion, can also call create_completion
26
27print(output['choices'][0]['text'].split("A:")[1].strip())
28
29# 我是一个人工智能聊天机器人,我的名字叫做“智慧助手”,我由一群程序员设计和开发的。我的主要任务就是通过与您交流来帮助您解决问题,为您提供相关的建议和支持。1# !pip install autoawq
2
3import torch
4from transformers import AutoTokenizer, AutoModelForCausalLM
5
6model_id = "XavierSpycy/Meta-Llama-3-8B-Instruct-zh-10k-AWQ"
7
8model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.float16, device_map="auto")
9tokenizer = AutoTokenizer.from_pretrained(model_id)
10
11prompt = "你好,你是谁?"
12
13messages = [
14 {"role": "system", "content": "你是一个乐于助人的助手。"},
15 {"role": "user", "content": prompt}]
16
17input_ids = tokenizer.apply_chat_template(
18 messages, add_generation_prompt=True, return_tensors="pt").to(model.device)
19
20terminators = [tokenizer.eos_token_id, tokenizer.convert_tokens_to_ids("<|eot_id|>")]
21
22outputs = model.generate(
23 input_ids,
24 max_new_tokens=256,
25 eos_token_id=terminators,
26 do_sample=True,
27 temperature=0.6,
28 top_p=0.9)
29
30response = outputs[0][input_ids.shape[-1]:]
31
32print(tokenizer.decode(response, skip_special_tokens=True))
33# 你好!我是一个人工智能助手,我的目的是帮助人们解决问题,回答问题,提供信息和建议。1# !pip install auto-gptq --no-build-isolation
2
3import torch
4from transformers import AutoTokenizer, AutoModelForCausalLM
5
6model_id = "XavierSpycy/Meta-Llama-3-8B-Instruct-zh-10k-GPTQ"
7
8model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.float16, device_map="auto")
9tokenizer = AutoTokenizer.from_pretrained(model_id)
10
11prompt = "什么是机器学习?"
12
13messages = [
14 {"role": "system", "content": "你是一个乐于助人的助手。"},
15 {"role": "user", "content": prompt}]
16
17input_ids = tokenizer.apply_chat_template(
18 messages, add_generation_prompt=True, return_tensors="pt").to(model.device)
19
20terminators = [tokenizer.eos_token_id, tokenizer.convert_tokens_to_ids("<|eot_id|>")]
21
22outputs = model.generate(
23 input_ids,
24 max_new_tokens=256,
25 eos_token_id=terminators,
26 do_sample=True,
27 temperature=0.6,
28 top_p=0.9)
29
30response = outputs[0][input_ids.shape[-1]:]
31
32print(tokenizer.decode(response, skip_special_tokens=True))
33# 机器学习是人工智能(AI)的一个分支,它允许计算机从数据中学习并改善其性能。它是一种基于算法的方法,用于从数据中识别模式并进行预测。机器学习算法可以从数据中学习,例如文本、图像和音频,并从中获得知识和见解。@article{llama3modelcard,
title={Llama 3 Model Card},
author={AI@Meta},
year={2024},
url = {https://github.com/meta-llama/llama3/blob/main/MODEL_CARD.md}}
@inproceedings{zheng2024llamafactory,
title={LlamaFactory: Unified Efficient Fine-Tuning of 100+ Language Models},
author={Yaowei Zheng and Richong Zhang and Junhao Zhang and Yanhan Ye and Zheyan Luo and Zhangchi Feng and Yongqiang Ma},
booktitle={Proceedings of the 62nd Annual Meeting of the Association for Computational Linguistics (Volume 3: System Demonstrations)},
address={Bangkok, Thailand},
publisher={Association for Computational Linguistics},
year={2024},
url={http://arxiv.org/abs/2403.13372}}