ColossalAI icon indicating copy to clipboard operation
ColossalAI copied to clipboard

[DOC]: How to do the supervised fine-tuning (SFT) (Stage 1 of chatGPT) ?

Open yaleimeng opened this issue 1 year ago • 9 comments

📚 The doc issue

We only see stage 2 and 3 in the chatpgt/example/readme file. Will you please show us how to finetune the gpt/blooom/opt model with an example dataset ?

yaleimeng avatar Mar 03 '23 01:03 yaleimeng

确实不知道,这个第一步怎么弄

chingfeng2021 avatar Mar 03 '23 06:03 chingfeng2021

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


I really don't know how to do this first step

Issues-translate-bot avatar Mar 03 '23 06:03 Issues-translate-bot

This issue says stage 1 is too simple to implement ... 😭

wqw547243068 avatar Mar 05 '23 15:03 wqw547243068

Simple or not, the absence of the first stage makes the entire demo incomplete. The finetuing for different models maybe very different. Many beginners feel confused about it. If the authors hasnot finished stage 1 themselves, how can they say easy? If the first step has been done, is there any difficulty in sharing relevant resources?

yaleimeng avatar Mar 05 '23 23:03 yaleimeng

I’ve spent some time drawing a diagram to illustrate the calling process, share with you all

image

Here is the code to fine-tune the Bloom model, petals

from petals import DistributedBloomForCausalLM

model = DistributedBloomForCausalLM.from_pretrained("bigscience/bloom-petals", tuning_mode="ptune", pre_seq_len=16)
# Embeddings & prompts are on your device, BLOOM blocks are distributed across the Internet

inputs = tokenizer("A cat sat", return_tensors="pt")["input_ids"]
outputs = model.generate(inputs, max_new_tokens=5)
print(tokenizer.decode(outputs[0]))  # A cat sat on a mat...

# Fine-tuning (updates only prompts or adapters hosted locally)
optimizer = torch.optim.AdamW(model.parameters())
for input_ids, labels in data_loader:
    outputs = model.forward(input_ids)
    loss = cross_entropy(outputs.logits, labels)
    optimizer.zero_grad()
    loss.backward()
    optimizer.step()

wqw547243068 avatar Mar 06 '23 08:03 wqw547243068

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


I’ve spent some time drawing a diagram to illustrate the calling process, share with you all

7V1Zc6O4Fv4t94GqmYdQElqAR+Ml3XWn76Qmmb7dTynFxjbTGDyAO8n8+pFYbEBy7CRAvDlT00Yb0jnfkY4+LdZQf/F0HbHl/Es4cX3NAJMnDQ00w4AGNvg/IuQ5CzFtkgXMIm+SJ9oE3Hr/uHkgyENX3sSNKwmTMPQTb1kNHIdB4I6TShiLovCxmmwa+tW3LtnMlQJux8yXQ//vTZJ5FmoZ5ib8k+vN5sWbIbWzmAUrEuctiedsEj6WgtBQQ/0oDJPs2+Kp7/pCeIVcsnyjLbHrikVukOyT4fH6uzPteX5yh+fXwc1fUdRbXFlZKT+Zv8ob3A/9MI6ZyNn7zP/Xn7Pk+uZOG1LNHmoOzb9YOG9V8lyIKnGfeEWcebLweQDkX+MkCn+4osSIhwRhwFM6U8/3a0HM92YBfxzzprg83PnpRonHldDLIxbeZCJe4zzOvcS9XbKxeOcjhxwPi8JVMHFFK4EoPgySHEbQTmMTlnhhkEdnVSpUiXiILMdctKIS7lMpKJfrtRsu3CR65knyWANB3chx/VzF7+MGNIaB9TzRvAQZlKdkOVJn6+I3yuRfcn2qdftfHP9N0N3X+f2M3SWzR/gNDK8MSbeSyjaig1uEW9JmWXGagaZE/OUSL4VnH0n7PIamn7XIJfkqtLBV5NggumVURI6JLHNoGbqpEPpaP41LHUlSTyLmBfeT1WLxrMfzRnUAHxh0DZWsAaDD3kjEFN0OrBmHWTI8350msian6achfWFZX1ShL6TWV2tGgreoaxmFi2USXxRWUhgBCoXhjhVG5F5tSDQbaFx4/IvV03qWNrTEAGX30sGqr/X6BzpY+ezB9R02/jFLw+svrym/pm0wEn/NaJuYlk7MiraRJWvbBh1qmm4xzWhxzlZp6nbV0yBYYZXA0EGXVmmesq8BoVE3DpWvwWc7yq4Qmm1JXfbey77G8rlRHUyIa03wto7yNfbRhEqQrJJDcCfsHe7EmenkIDyGwtW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hgheWrlSOflesVx7jRuwmz/BAaErXPKrOTXZ6jAfLxGq+i0fS34lOJJC9uVDmgOYSWOb+Avlww7t0wiYmkw9T7bPW3IQ1UFzbfGEolpQJ7Pg+R5l6Stowhw8VPbKpXj7tDw5QD8d+a8TGscLQqrhW+mE4V+k7b9zI4woTY2/TB94KS9rpcWGgBut7bwbio60FX/aS9va4bFsqq2NOHCvusThSg3jrTMMuWcMV0EF6kr5Rk+DZW7SIYmvfbotoZw6CQUMTb2xW14cMirq1BcVdH2dmC2abI8OhmMEWL+a9ZtDUPBxbNTMwOzYDebWBY44l7sxzm92+vcVd5TEPmBKAO/BZCSDS5FkxS7M6XoLDZ058w3I/9Lpb0TomAPd2R9vZmLS+SfK9viiurXsasONeR6a8B4Ob26zjafYSXN7t2BPlZUzM5b240UG3gy1bR+ZmplydBKiuxoLd3u6CZSb2f4zD9FQVgijWy9QFoIemESIzqsV5kd7nU1ULhRKJqlIFhV0q4kx3T37sOLu3d9/ORUeE2lsXWV471FKM6mXZ3Q62RKajLxDeOml9LWn6IbBv59JoCqruJXzrlb20cJSLgjq+r5ecDvF/QXzJH2oe8bA2oQJvRTypIb7ju+yIzOyHy8RbcDBETbuJH83iUGrqgNqbT1XyB0DokGPnlo+NmCl4kN39SDtbcQ3QEDFjmNUTAl2vEBKZDk77kS76kI42LmCsQ6PUe9iHt3GBnDkhfDQ7QoubiHb3Oy0RwrV+R/qpob37nXoH1vHRbHLse6C7227zBrtqEvH7nlKl7XjsGME6R4jq/fC+oCdWDfT1Q94tg57KJO9J7c4kpH411iEMrlRmdL1g6vJGjd1z+wVGFb0OiN7lDUxUZicTN07ux753zj+xLN2VRRU3CEPQ8Q+zUAWxNqSaQ4prNkeaTfLf1TGd9CeANaNfXNRpDiR1nvtxjvpvYKm0vFbnO1XMH6NQ3E67GcO4xcy/iJ+e5YH/Ag=="}">

Issues-translate-bot avatar Mar 06 '23 08:03 Issues-translate-bot

I’ve spent some time drawing a diagram to illustrate the calling process, share with you all

image

Here is the code to fine-tune the Bloom model, petals

from petals import DistributedBloomForCausalLM

model = DistributedBloomForCausalLM.from_pretrained("bigscience/bloom-petals", tuning_mode="ptune", pre_seq_len=16)
# Embeddings & prompts are on your device, BLOOM blocks are distributed across the Internet

inputs = tokenizer("A cat sat", return_tensors="pt")["input_ids"]
outputs = model.generate(inputs, max_new_tokens=5)
print(tokenizer.decode(outputs[0]))  # A cat sat on a mat...

# Fine-tuning (updates only prompts or adapters hosted locally)
optimizer = torch.optim.AdamW(model.parameters())
for input_ids, labels in data_loader:
    outputs = model.forward(input_ids)
    loss = cross_entropy(outputs.logits, labels)
    optimizer.zero_grad()
    loss.backward()
    optimizer.step()

Awesome! Thank you so much. Fantastic work, it is amazing. We are considering to restructure the code, your pic will be a good reference.

ht-zhou avatar Mar 07 '23 02:03 ht-zhou

Simple or not, the absence of the first stage makes the entire demo incomplete. The finetuing for different models maybe very different. Many beginners feel confused about it. If the authors hasnot finished stage 1 themselves, how can they say easy? If the first step has been done, is there any difficulty in sharing relevant resources?

We do not have the plan to implement stage1 soon, you can refer to https://github.com/hpcaitech/ColossalAI-Examples/tree/main/language to implement the code. We hope that more people can participate in our open source projects and contribute to us. Thanks a lot !!

ht-zhou avatar Mar 07 '23 02:03 ht-zhou

@yaleimeng Thanks for your proposal, it will take time and we have more important work now Stage 1 is a simple supervised learning process, and we have plans to add a wiki page for this project in the future so that newcomers who do not understand the field can get started quickly. We will rely more on the ecology of hugging face, so that users can focus more on the implementation of the whole RLHF process rather than the model.

Fazziekey avatar Mar 07 '23 02:03 Fazziekey

thanks for answering。That's very helpful.

yaleimeng avatar Mar 08 '23 01:03 yaleimeng