Skip to main content

Humanable ChatGPT/GLM Fine-tuning.

Project description

使用

先clone仓库或pip安装:

pip install hcgf

需要的依赖在requirements.txt中,通过下面命令安装:

pip install -r requirements.txt

注意:不支持PyTorch2.0,历史版本请参考下面链接安装:

https://pytorch.org/get-started/previous-versions/

准备数据

每一行一个json,必须包含promptcompletion两个字段。示例如下:

{"prompt": "问题:你是谁?\n", "completion": "不告诉你。"},

正常微调

至少需要一张16G显存的卡。

# 微调
import hcgf
gl = hcgf.GlmLora("THUDM/chatglm-6b", device="cuda:0")
gl.load_data("./data/chatgpt_finetune_faq.json").tune()

# 推理
import hcgf
gl = hcgf.GlmLora("THUDM/chatglm-6b", device="cuda:0", infer_mode=True)
gl.load_pretrained("/path/to/lora_pt").eval()
inp = "你是谁?"
gl.chat(inp)

8bit微调

至少需要一张12G显存的卡。不指定device。

# 微调
import hcgf
gl = hcgf.GlmLora("THUDM/chatglm-6b", load_in_8bit=True)
gl.load_data("./data/chatgpt_finetune_faq.json").tune()

# 推理
gl = hcgf.GlmLora("THUDM/chatglm-6b", load_in_8bit=True, infer_mode=True)
gl.load_pretrained("/path/to/lora_pt").eval()
inp = "你是谁?"
gl.chat(inp)

配置

有几个影响显存的参数可以配置:max_seq_lenbatch_sizeaccumulate_steps

(
gl
.load_data("./data/chatgpt_finetune_faq.json", max_seq_len=128)
.tune(batch_size=1, accumulate_steps=1)
)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hcgf-0.0.3.tar.gz (39.0 kB view hashes)

Uploaded Source

Built Distribution

hcgf-0.0.3-py3-none-any.whl (39.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page