Skepsun/lawyer_llama_data
Viewer • Updated • 21.5k • 42 • 12
How to use basuo/llama-law with llama-cpp-python:
# !pip install llama-cpp-python from llama_cpp import Llama llm = Llama.from_pretrained( repo_id="basuo/llama-law", filename="unsloth.Q4_K_M.gguf", )
llm.create_chat_completion( messages = "No input example has been defined for this model task." )
How to use basuo/llama-law with llama.cpp:
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf basuo/llama-law:Q4_K_M # Run inference directly in the terminal: llama cli -hf basuo/llama-law:Q4_K_M
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf basuo/llama-law:Q4_K_M # Run inference directly in the terminal: llama cli -hf basuo/llama-law:Q4_K_M
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf basuo/llama-law:Q4_K_M # Run inference directly in the terminal: ./llama-cli -hf basuo/llama-law:Q4_K_M
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf basuo/llama-law:Q4_K_M # Run inference directly in the terminal: ./build/bin/llama-cli -hf basuo/llama-law:Q4_K_M
docker model run hf.co/basuo/llama-law:Q4_K_M
How to use basuo/llama-law with Ollama:
ollama run hf.co/basuo/llama-law:Q4_K_M
How to use basuo/llama-law with Unsloth Studio:
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for basuo/llama-law to start chatting
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for basuo/llama-law to start chatting
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for basuo/llama-law to start chatting
How to use basuo/llama-law with Docker Model Runner:
docker model run hf.co/basuo/llama-law:Q4_K_M
How to use basuo/llama-law with Lemonade:
# Download Lemonade from https://lemonade-server.ai/ lemonade pull basuo/llama-law:Q4_K_M
lemonade run user.llama-law-Q4_K_M
lemonade list
本模型是基于llama3.1-8B-Chinese-Chat预训练模型基础上再次训练的法律条文模型。
本模型基于llama3.1-8B-Chinese-Chat预训练模型,在法律条文数据集上进行了微调,使用的微调算法是LoRA。
训练框架:unsloth
训练参数:
per_device_train_batch_size = 2, # 每个设备的训练批量大小
gradient_accumulation_steps = 4, # 梯度累积步数
warmup_steps = 5,
max_steps = 60, # 最大训练步数,测试时设置
# num_train_epochs= 5, # 训练轮数
logging_steps = 10, # 日志记录频率
save_strategy = "steps", # 模型保存策略
save_steps = 100, # 模型保存步数
learning_rate = 2e-4, # 学习率
fp16 = not torch.cuda.is_bf16_supported(), # 是否使用float16训练
bf16 = torch.cuda.is_bf16_supported(), # 是否使用bfloat16训练
optim = "adamw_8bit", # 优化器
weight_decay = 0.01, # 正则化技术,在损失函数中添加正则化项来减小权重的大小
lr_scheduler_type = "linear", # 学习率衰减策略
seed = 3407, # 随机种子
from huggingface_hub import snapshot_download
snapshot_download(repo_id="basuo/llama-law", ignore_patterns=["*.gguf"]) # Download our BF16 model without downloading GGUF models.
模型推理:
import torch
from unsloth import FastLanguageModel
model, tokenizer = FastLanguageModel.from_pretrained(
model_name = "/Your/Local/Path/to/llama-law",
max_seq_length = 2048,
dtype = torch.float16,
load_in_4bit = True,
)
FastLanguageModel.for_inference(model)
alpaca_prompt = """
下面是一项描述任务的说明,配有提供进一步背景信息的输入。写出一个适当完成请求的回应。
### Instruction:
{}
### Input:
{}
### Response:
{}
"""
inputs = tokenizer(
[
alpaca_prompt.format(
"没有赡养老人就无法继承财产吗?", # instruction
"", # input
"", # output
)
], return_tensors = "pt").to("cuda")
outputs = model.generate(**inputs, max_new_tokens = 64, use_cache = True)
tokenizer.batch_decode(outputs)
['\n下面是一项描述任务的说明,配有提供进一步背景信息的输入。写出一个适当完成请求的回应。\n\n### Instruction:\n没有赡养老人就无法继承财产吗?\n\n### Input:\n\n\n### Response:\n\n不是的,根据《中华人民共和国继承法》规定,继承人应当履行赡养义务,未履行赡养义务的,应当承担赡养费用。因此,如果没有赡养老人,继承人可以继承财产,但需要承担']