Code Monkey home page Code Monkey logo

phogpt-7.5b-fine-tuning-qlora's Introduction

PhoGPT-7.5B-Fine-tuning-QLoRA

  • Author: Mr.Jack _ Công ty www.BICweb.vn
  • Start Date: 23 Dec-2023
  • End Date: 05 Feb-2024

Fundamental:

Sự kiện:

Lý do:

  • Khi mà trên thế giới tràn ngập các model English only với quy mô từ nhỏ (1M-33M-124M), vừa (355M-774M-1.5B) đến lớn (3B-7B-13B-34B) và khổng lồ (70B-180B) với độ trả lời câu hỏi chính xác khá cao, nhưng ở Việt Nam thì chưa thấy có model chat nào quy mô khoảng 7B dùng được :( thì việc fine-tuning được một em ChatGPT biết "ăn nói nhẹ nhàng" ở nhà để vọc vạch là "ước mơ" của bao đời lập trình viên chứ không của riêng ai. Vì vậy khi VinAi công bố model PhoGPT-7.5B là mình cũng thấy rất hào hứng và muốn bắt tay vào fine-tuning em nó để phục vụ mục đích nghiên cứu và học tập.
  • Mình chia sẻ kết quả này là để động viên anh em "ngành" hãy cứ mạnh dạn Fine-tuning PhoGPT-7.5B (hoặc các Model-7B nói chung) bằng bộ thư viện PEFT-QLoRA thì khá nhẹ và nhanh chứ không bị nặng và lâu đâu nhé. Mỗi item chỉ train khoảng 1s trên Colab T4 là quá ổn nhé vì train bằng QLoRA nên số lượng params train rất ít mà kết quả vẫn Ok ^^

Fine-tuning model PhoGPT-7.5B

  • Model architecture: MPT-7B (https://www.databricks.com/blog/mpt-7b)
  • Cấu hình tối thiểu: GPU 15GB ~ Colab T4
  • Source code thì … copy-paste … không phải làm gì nhiều vì bộ thư viện Transformers và Peft nó làm gần hết việc rồi, chỉ mỗi cấu hình Trainer 😂
  • Dataset cá nhân siêu nhỏ, tuỳ nhu cầu sử dụng
  • Thời gian train ~1s/item
  • File LoRA khá nhỏ gọn ~256MB, tổng cộng tất cả các files của 1 checkpoint khoảng dưới 800MB
  • Training loss xuống cũng khá nhanh, nhưng lại không bị Overfit sớm
  • Khi dùng Peft Fine-tuning với QLoRA-4bit thì giảm được bộ nhớ GPU rất nhiều nên chỉ cần dùng em T4-15GB colab, nhưng Inference 16bfloat thì lại phải gọi đến em V100-16GB colab
  • Ví dụ: nếu doanh nghiệp bạn có khoảng 1000 câu hỏi đáp, thì dataset sẽ là 1000 items, Fine-tuning khoảng 30 epoch (ChatGPT-3 fine-tuning khoảng 16 epochs ?! để overfit dữ liệu; còn GPT2 thì "We then fine-tuned a model on each of the datasets, with 500 training epochs per model 😂, a threshold chosen to prevent overfitting."_page4 of https://arxiv.org/pdf/1908.09203.pdf) để cho em nó overfit thì 1000 items x 30 epochs = 30.000 iterations / 3600s = 8.33h Nvidia Tesla T4 colab x $0.42/h = $3.58 ~> một chi phí quá ổn cho một em lễ tân "của nhà trồng được" nhé 😂

alt text

alt text

Update 05/02/2024 - 01PM:

bnb_config = BitsAndBytesConfig(

  • load_in_4bit=True,
  • bnb_4bit_use_double_quant=True,
  • bnb_4bit_quant_type="nf4",
  • bnb_4bit_compute_dtype="float16")

model = AutoModelForCausalLM.from_pretrained(

  • mode_id,
  • quantization_config=bnb_config,
  • device_map="cua",
  • trust_remote_code=True)

alt text

peft_config = LoraConfig(

  • r=32,
  • lora_alpha=32,
  • target_modules=["attn.Wqkv", "attn.out_proj", "ffn.up_proj", "ffn.down_proj"],
  • lora_dropout=0.05,
  • bias="none",
  • task_type="CAUSAL_LM")

training_arguments = TrainingArguments(

  • output_dir=output_model,
  • per_device_train_batch_size=1,
  • gradient_accumulation_steps=1,
  • optim="paged_adamw_32bit",
  • learning_rate=1e-4,
  • lr_scheduler_type="cosine",
  • save_strategy="steps",
  • save_steps=50,
  • logging_steps=10,
  • num_train_epochs=100,
  • max_steps=100,
  • fp16=True)

trainer = SFTTrainer(

  • model=model,
  • train_dataset=data,
  • peft_config=peft_config,
  • dataset_text_field="text",
  • args=training_arguments,
  • tokenizer=tokenizer,
  • packing=False,
  • max_seq_length=1024)

Sử dụng model mặc định, chưa qua fine-tuning:

alt text

alt text

alt textalt text

Update 23Feb2024 - 08PM

Test thử em vinai/PhoGPT-4B-Chat-v0.1 thấy cũng hay phết ^.^ Cấu hình chạy cũng nhẹ nhàng, chỉ cần dùng Colab-T5 là dùng được, mà chỉ cần chạy có 50% là khoảng 7GB GPU thôi nhé.

  • Model: vinai/PhoGPT-4B-Chat-v0.1
  • Type: Instruction following & Chat
  • Model Size: 3.7B
  • Context length: 8192
  • Vocab size: 20K
  • Training data size: 70K instructional prompt and response pairs & 290K conversations
  • Note: PROMPT_TEMPLATE = "### Câu hỏi: {instruction}\n### Trả lời:"

alt text

phogpt-7.5b-fine-tuning-qlora's People

Contributors

mr-jack-tung avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

htdung167 quyen88

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.