🚀 代碼LLaMA 7B指令Solidity模型
這是一個經過微調的70億參數的代碼LLaMA指令模型,藉助PEFT庫提供的4位QLoRA微調技術,用於生成Solidity智能合約。該模型能夠有效解決在區塊鏈開發中生成智能合約代碼的問題,為開發者提供高效、準確的代碼生成能力。
✨ 主要特性
- 代碼生成:可生成Solidity智能合約代碼。
- 微調技術:採用4位QLoRA微調技術,優化模型性能。
📦 安裝指南
文檔未提供安裝步驟,此部分跳過。
💻 使用示例
基礎用法
from transformers import BitsAndBytesConfig, AutoTokenizer, AutoModelForCausalLM
import torch
import accelerate
use_4bit = True
bnb_4bit_compute_dtype = "float16"
bnb_4bit_quant_type = "nf4"
use_double_nested_quant = True
compute_dtype = getattr(torch, bnb_4bit_compute_dtype)
bnb_config = BitsAndBytesConfig(
load_in_4bit=use_4bit,
bnb_4bit_use_double_quant=use_double_nested_quant,
bnb_4bit_quant_type=bnb_4bit_quant_type,
bnb_4bit_compute_dtype=compute_dtype,
load_in_8bit_fp32_cpu_offload=True
)
tokenizer = AutoTokenizer.from_pretrained("AlfredPros/CodeLlama-7b-Instruct-Solidity")
model = AutoModelForCausalLM.from_pretrained("AlfredPros/CodeLlama-7b-Instruct-Solidity", quantization_config=bnb_config, device_map="balanced_low_0")
input='Make a smart contract to create a whitelist of approved wallets. The purpose of this contract is to allow the DAO (Decentralized Autonomous Organization) to approve or revoke certain wallets, and also set a checker address for additional validation if needed. The current owner address can be changed by the current owner.'
prompt = f"""### Instruction:
Use the Task below and the Input given to write the Response, which is a programming code that can solve the following Task:
### Task:
{input}
### Solution:
"""
input_ids = tokenizer(prompt, return_tensors="pt", truncation=True).input_ids.cuda()
outputs = model.generate(input_ids=input_ids, max_new_tokens=1024, do_sample=True, top_p=0.9, temperature=0.001, pad_token_id=1)
print(tokenizer.batch_decode(outputs.detach().cpu().numpy(), skip_special_tokens=True)[0][len(prompt):])
📚 詳細文檔
訓練數據集
用於微調模型的數據集是AlfredPros的智能合約指令數據集(https://huggingface.co/datasets/AlfredPros/smart-contracts-instructions)。該數據集包含6003個由GPT生成的人類指令與Solidity源代碼數據對,並且已經過處理,可用於訓練大語言模型。
訓練參數
Bitsandbytes量化配置
- 以4位加載:true
- 4位量化類型:NF4
- 4位計算數據類型:float16
- 4位使用雙重量化:true
監督式微調訓練器參數
- 訓練輪數:1
- FP16:true
- FP16選項級別:O1
- BF16:false
- 每個設備的訓練批次大小:1
- 梯度累積步數:1
- 梯度檢查點:true
- 最大梯度範數:0.3
- 學習率:2e - 4
- 權重衰減:0.001
- 優化器:分頁AdamW 32位
- 學習率調度器類型:餘弦
- 預熱比例:0.03
訓練詳情
- 使用的GPU:1x NVIDIA GeForce GTX 1080Ti
- 訓練時間:21小時4分57秒
訓練損失
Step Training Loss
100 0.330900
200 0.293000
300 0.276500
400 0.290900
500 0.306100
600 0.302600
700 0.337200
800 0.295000
900 0.297800
1000 0.299500
1100 0.268900
1200 0.257800
1300 0.264100
1400 0.294400
1500 0.293900
1600 0.287600
1700 0.281200
1800 0.273400
1900 0.266600
2000 0.227500
2100 0.261600
2200 0.275700
2300 0.290100
2400 0.290900
2500 0.316200
2600 0.296500
2700 0.291400
2800 0.253300
2900 0.321500
3000 0.269500
3100 0.295600
3200 0.265800
3300 0.262800
3400 0.274900
3500 0.259800
3600 0.226300
3700 0.325700
3800 0.249000
3900 0.237200
4000 0.251400
4100 0.247000
4200 0.278700
4300 0.264000
4400 0.245000
4500 0.235900
4600 0.240400
4700 0.235200
4800 0.220300
4900 0.202700
5000 0.240500
5100 0.258500
5200 0.236300
5300 0.267500
5400 0.236700
5500 0.265900
5600 0.244900
5700 0.297900
5800 0.281200
5900 0.313800
6000 0.249800
6003 0.271939
📄 許可證
本項目使用的許可證為llama2。
屬性 |
詳情 |
模型類型 |
代碼LLaMA 7B指令Solidity模型 |
訓練數據 |
AlfredPros的智能合約指令數據集 |