Commit afe180a6 authored by wanglch's avatar wanglch
Browse files

Initial commit

parents
Pipeline #1006 canceled with stages
This image diff could not be displayed because it is too large. You can view the blob instead.
import torch
from peft import PeftModel
from transformers import AutoTokenizer, AutoModel
base_model_path = '../Finllm/Finllm_computing'
lora_model_path = '../saves/Finllm_computing_train/lora/sft/checkpoint-4000'
new_model_path = '../Finllm/Finllm_computing-merged'
# Loading the base model and tokenzier
model = AutoModel.from_pretrained(
base_model_path, torch_dtype=torch.float16, trust_remote_code=True
)
tokenzier = AutoTokenizer.from_pretrained(
base_model_path, trust_remote_code=True
)
# Loading the LoRA adapter
lora_model = PeftModel.from_pretrained(model, lora_model_path, torch_dtype=torch.float16,)
# Applying the LoRA
new_model = lora_model.merge_and_unload()
# Saving the target model to new model paths
new_model.save_pretrained(new_model_path)
tokenzier.save_pretrained(new_model_path)
\ No newline at end of file
# 模型唯一标识
modelCode = 631
# 模型名称
modelName=DISC-FinLLM_pytorch
# 模型描述
modelDescription=开源免费可商用的预训练多任务金融大模型可用于情绪分析, 关键词提取, 标题生成以及金融词提取,问答等。
# 应用场景
appScenario=推理,训练,金融,教育,政府,科研
# 框架类型
frameType=pytorch
#!/bin/bash
deepspeed --master_port $(shuf -n 1 -i 10000-65535) --include="localhost:3,4" /DISC-FinLLM_ModelZoo/LLaMA-Factory/src/train_bash.py \
--deepspeed /DISC-FinLLM_ModelZoo/LLaMA-Factory/deepspeed.json \
--stage sft \
--do_train \
--model_name_or_path /DISC-FinLLM_ModelZoo/FinLLM \
--dataset retrieval_part \
--dataset_dir /DISC-FinLLM_ModelZoo/LLaMA-Factory/data \
--template baichuan2 \
--finetuning_type lora \
--lora_target all \
--output_dir /DISC-FinLLM_ModelZoo/saves/lora_multi.py \
--overwrite_output_dir \
--cutoff_len 1024 \
--preprocessing_num_workers 4 \
--per_device_train_batch_size 16 \
--per_device_eval_batch_size 4 \
--gradient_accumulation_steps 1 \
--lr_scheduler_type cosine \
--logging_steps 10 \
--warmup_steps 20 \
--save_steps 100 \
--eval_steps 100 \
--evaluation_strategy steps \
--load_best_model_at_end \
--learning_rate 5e-5 \
--num_train_epochs 10.0 \
--max_samples 3000 \
--val_size 0.1 \
--ddp_timeout 180000000 \
--plot_loss \
--fp16
HIP_VISIBLE_DEVICES=6 python /DISC-FinLLM_ModelZoo/LLaMA-Factory/src/train_bash.py \
--stage sft \
--do_train \
--model_name_or_path /DISC-FinLLM_ModelZoo/FinLLM \
--dataset retrieval_part \
--dataset_dir /DISC-FinLLM_ModelZoo/LLaMA-Factory/data \
--template baichuan2 \
--finetuning_type lora \
--lora_target all \
--output_dir /DISC-FinLLM_ModelZoo/saves/lora \
--overwrite_cache \
--overwrite_output_dir \
--cutoff_len 1024 \
--preprocessing_num_workers 1 \
--per_device_train_batch_size 1 \
--per_device_eval_batch_size 1 \
--gradient_accumulation_steps 1 \
--lr_scheduler_type cosine \
--logging_steps 10 \
--warmup_steps 20 \
--save_steps 100 \
--eval_steps 100 \
--evaluation_strategy steps \
--learning_rate 5e-5 \
--num_train_epochs 3.0 \
--max_samples 3000 \
--val_size 0.1 \
--ddp_timeout 180000000 \
--plot_loss True \
--fp16
import hashlib
def calculate_sha1(file_path):
sha1_hash = hashlib.sha1()
with open(file_path,"rb") as f:
# Read and update hash string value in blocks of 4K
for byte_block in iter(lambda: f.read(4096),b""):
sha1_hash.update(byte_block)
return sha1_hash.hexdigest()
print(calculate_sha1("/home/wanglch/projects/LLaMA-Factory/data/retrieval_part.json")) # c25232270e00337ca3889a04b5ae023129c7c154
\ No newline at end of file
import json
import torch
import streamlit as st
from transformers import AutoModelForCausalLM, AutoTokenizer
from transformers.generation.utils import GenerationConfig
st.set_page_config(page_title="FudanDISC-FinLLM")
st.title("FudanDISC-FinLLM🤖️")
@st.cache_resource
def init_model():
model_path = "/DISC-FinLLM/FinLLM"
model = AutoModelForCausalLM.from_pretrained(
model_path, torch_dtype=torch.float16, device_map="auto", trust_remote_code=True
)
model.generation_config = GenerationConfig.from_pretrained(model_path)
tokenizer = AutoTokenizer.from_pretrained(
model_path, use_fast=False, trust_remote_code=True
)
return model, tokenizer
def clear_chat_history():
del st.session_state.messages
def init_chat_history():
with st.chat_message("assistant", avatar="🤖"):
st.markdown("您好,我是复旦 DISC-FinLLM,很高兴为您服务💖")
if "messages" in st.session_state:
for message in st.session_state.messages:
avatar = "🙋‍♂️" if message["role"] == "user" else "🤖"
with st.chat_message(message["role"], avatar=avatar):
st.markdown(message["content"])
else:
st.session_state.messages = []
return st.session_state.messages
def main():
model, tokenizer = init_model()
messages = init_chat_history()
if prompt := st.chat_input("Shift + Enter 换行,Enter 发送"):
with st.chat_message("user", avatar="🙋‍♂️"):
st.markdown(prompt)
messages.append({"role": "user", "content": prompt})
print(f"[user] {prompt}", flush=True)
with st.chat_message("assistant", avatar="🤖"):
placeholder = st.empty()
for response in model.chat(tokenizer, messages, stream=True):
placeholder.markdown(response)
if torch.backends.mps.is_available():
torch.mps.empty_cache()
messages.append({"role": "assistant", "content": response})
print(json.dumps(messages, ensure_ascii=False), flush=True)
st.button("清空对话", on_click=clear_chat_history)
if __name__ == "__main__":
main()
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment