高效金融领域量化LLM的精细调优
要加载使用transformers和bitsandbytes的4位模型,您需要从源代码安装accelerate和transformers,并确保拥有最新版本的bitsandbytes库(0.39.0)。
pip3 install -r requirements.txt
如果要在新实例上进行模型的微调,您可以运行setup.sh安装python和cuda软件包。
bash scripts/setup.sh
bash script/finetune.sh
量化参数由BitsandbytesConfig控制
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
pretrained_model_name_or_path = "bavest/fin-llama-33b-merge"
model = AutoModelForCausalLM.from_pretrained(
pretrained_model_name_or_path=pretrained_model_name_or_path,
load_in_4bit=True,
device_map='auto',
torch_dtype=torch.bfloat16,
quantization_config=BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_compute_dtype=torch.bfloat16,
bnb_4bit_use_double_quant=True,
bnb_4bit_quant_type='nf4'
),
)
tokenizer = AutoTokenizer.from_pretrained(pretrained_model_name_or_path)
question = "What is the market cap of apple?"
input = "" # context if needed
prompt = f"""
A chat between a curious human and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's question.
'### Instruction:\n{question}\n\n### Input:{input}\n""\n\n### Response:
"""
input_ids = tokenizer.encode(prompt, return_tensors="pt").to('cuda:0')
with torch.no_grad():
generated_ids = model.generate(
input_ids,
do_sample=True,
top_p=0.9,
temperature=0.8,
max_length=128
)
generated_text = tokenizer.decode(
[el.item() for el in generated_ids[0]], skip_special_tokens=True
)
数据集发布在bigscience-openrail-m下。您可以在HF上找到用于训练FIN-LLAMA模型的数据集 bavest/fin-llama-dataset 。
以下是已知问题和错误的列表。如果您的问题在此处未报告,请打开新的问题并描述问题。有关其他限制,请参见 QLORA 。
我们还要感谢Meta发布了LLaMA模型,否则本工作将无法实现。
此存储库构建在 Stanford Alpaca 、 QLORA 、 Chinese-Guanaco 和 LMSYS FastChat 存储库的基础上。
我们根据GLP3许可证在此存储库中发布与QLoRA微调相关的资源。此外,我们还发布7B、13B、33B和65B的基本LLaMA模型的FIN-LLAMA模型系列。这些模型旨在用于与LLaMA许可证一致的目的,并需要访问LLaMA模型。
我希望您担任会计师,并提出管理财务的创造性方法。在为客户创建财务计划时,您需要考虑预算、投资策略和风险管理,以及在某些情况下,您还需要提供有关税法和法规的建议,以帮助他们最大化利润。我首先的建议请求是“为中小企业创建一个注重成本节约和长期投资的财务计划”。
可以使用参数 --optim paged_adamw_32bit 访问分页优化器
@misc{Fin-LLAMA,
author = {William Todt, Ramtin Babaei, Pedram Babaei},
title = {Fin-LLAMA: Efficient Finetuning of Quantized LLMs for Finance},
year = {2023},
publisher = {GitHub},
journal = {GitHub repository},
howpublished = {\url{https://github.com/Bavest/fin-llama}},
}