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()
gl.chat("你是谁?")

8bit微调

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

需要安装依赖: bitsandbytes

# 微调
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()
gl.chat("你是谁?")

配置

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

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

不同配置 8bit 资源占用:

max_seq_len batch_size memory
64 1 11G
128 1 12G
512 1 22G
128 2 15G
128 4 21G

不同配置正常资源占用:

max_seq_len batch_size memory
64 1 15G
128 1 16G
512 1 30G
128 2 19G
128 4 25G

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.4.tar.gz (37.8 kB view details)

Uploaded Source

Built Distribution

hcgf-0.0.4-py3-none-any.whl (39.8 kB view details)

Uploaded Python 3

File details

Details for the file hcgf-0.0.4.tar.gz.

File metadata

  • Download URL: hcgf-0.0.4.tar.gz
  • Upload date:
  • Size: 37.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.64.1 CPython/3.8.13

File hashes

Hashes for hcgf-0.0.4.tar.gz
Algorithm Hash digest
SHA256 d0b2c374f4510e541580caab8b0173bb98fde219f126bf5ae29a60efdaa722d3
MD5 ecab4e2d7e23eb225429ec3c0f81e593
BLAKE2b-256 706827a005648675f32ff4ae4cc433c7b73451d22e92b7c4842001b128281e6d

See more details on using hashes here.

Provenance

File details

Details for the file hcgf-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: hcgf-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 39.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.64.1 CPython/3.8.13

File hashes

Hashes for hcgf-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 88b2e0cfb8a27619c629bf874294b6a6191e7e7065a9d205facecba1e94de16d
MD5 8a4f05e516267b2366cd3f135d4a5b25
BLAKE2b-256 37c9167c5d5d95d6ddd37a29261082767221033eeeb4f80fbe14f72a054f0be0

See more details on using hashes here.

Provenance

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