How eddaoudi-mohamed/baby_care_chatboot works
Project type and purpose
• This is an ML fine-tuning toolkit for the ChatGLM-6B language model using the P-Tuning v2 method. Its primary purpose is to run parameter-efficient training, quantization, and evaluation on advertisement-generation (ADGEN) or custom datasets. It embeds into a command-line interface (shell scripts) that drives Python modules for training, evaluation, and optional web demo.
File structure
• Top-level files:
• README.md – project overview and usage
• requirements.txt – Python dependencies
• train.sh, evaluate.sh – shell scripts invoking training and evaluation
• ptuning/ directory:
• main.py – entry point parsing args and dispatching tasks
• arguments.py – CLI argument definitions and default configs
• trainer.py, trainer_seq2seq.py – training logic (P-Tuning v2, full fine-tune, seq2seq trainer)
• deepspeed.json – DeepSpeed config for distributed or ZeRO training
• (Other scripts mentioned: ds_train_finetune.sh, train_chat.sh, web_demo.sh are analogous to train.sh/evaluate.sh)
README for additional insights
• Describes dataflow: download ADGEN dataset → configure prompt lengths, quantization bits → run train.sh (P-Tuning v2) or ds_train_finetune.sh (full fine-tune) → outputs prefix encoder checkpoint → run evaluate.sh for metrics (Rouge, BLEU)
• Mentions usage of Huggingface Transformers, PyTorch, Deepspeed, quantization, and optional web demo.
a. Main components:
1. Shell Script Layer: train.sh, ds_train_finetune.sh, evaluate.sh, train_chat.sh, web_demo.sh
2. CLI Module: ptuning/main.py & arguments.py
3. Data Pipeline:
– DataLoader reading JSON dataset (ADGEN or custom)
– Tokenizer (from transformers AutoTokenizer)
4. Model Core:
– Base ChatGLM-6B model (pretrained, loaded from Huggingface or local path)
– PrefixEncoder (soft prompts)
5. Training Engine:
– P-Tuning v2 logic in trainer.py (freeze base model, train only PrefixEncoder)
– Seq2Seq or full fine-tune logic in trainer_seq2seq.py / ds_train_finetune.sh + DeepSpeed
– Quantization module (model.quantize(4), .half(), .cuda())
– Gradient accumulation and checkpointing
6. Evaluation Engine:
– Prefix checkpoint + base model loader
– Generation engine (.chat or .generate)
– Metric calculators (ROUGE, BLEU)
7. External Services & Storage:
– Huggingface Hub (model checkpoint repository)
– Cloud storage (Google Drive / Tsinghua) for data
– Local filesystem for output predictions and logs
b. Relationships / Data flow:
• Shell Script → invokes CLI Module → parses arguments → selects Data Pipeline & Training Engine → loads model → runs training → writes checkpoints
• After training, Shell Script → invokes CLI Module in evaluation mode → loads base model + prefix weights → runs generation → pipes outputs to Evaluation Engine → writes metrics and generated_predictions.txt
• Optional web_demo.sh → runs a small HTTP server / interactive loop loading the same model + prefix weights
c. Architectural patterns / design principles
• Modular separation via CLI module vs. core training logic
• Plug-and-play trainer classes (P-Tuning v2 vs. full fine-tune vs. seq2seq)
• Use of external config (deepspeed.json) for scalable multi-GPU / ZeRO
• Shell-script façade abstracts environment variables, hyperparameters
d. Key technologies / frameworks
• Python 3 + PyTorch
• Huggingface Transformers library (AutoTokenizer, AutoModel)
• Deepspeed for distributed / ZeRO training
• Model quantization APIs (INT4, FP16)
• Datasets library for JSON loading
• nltk, jieba, rouge-chinese for evaluation
• Shell scripting for orchestration