AYURVEDA GEMMA-4 TRAINING - CELL SCRIPTS
=========================================

These are 11 Python scripts designed to run as Jupyter notebook cells.
Run them one by one in order. If any cell fails, fix the issue and re-run that cell.

REQUIREMENTS
------------
- Python 3.10+
- PyTorch with CUDA
- unsloth (pip install unsloth)
- transformers, datasets, trl, accelerate

QUICK START
-----------
1. Open Jupyter Notebook or JupyterLab
2. In the first cell, run: %run cell_01_config.py
3. In the second cell, run: %run cell_02_imports.py
4. Continue through all 11 cells

CELLS
-----
cell_01_config.py    - Set paths, model name, hyperparameters
cell_02_imports.py   - Import packages, check CUDA
cell_03_dataset.py   - Load 1.69GB dataset, standardize ShareGPT format
cell_04_model.py     - Load Gemma-4 model from local cache
cell_05_lora.py      - Attach LoRA adapter (r=64, alpha=128)
cell_06_args.py      - Configure training arguments (LR, epochs, scheduler)
cell_07_trainer.py   - Initialize SFTTrainer
cell_08_train.py     - START TRAINING (4-6 hours on A4000)
cell_09_save.py      - Save LoRA adapter (~100 MB)
cell_10_merge.py     - OPTIONAL: Merge into full model (needs more VRAM)
cell_11_test.py      - Test inference with your trained model

SWITCHING TO BIGGER MODEL
-------------------------
In cell_01_config.py, change MODEL_NAME:
  "unsloth/gemma-4-E2B-it"    - 5B params, fits 16GB (A4000)
  "unsloth/gemma-4-12b-it"    - 12B params, needs 24GB+ (3090/4090)
  "unsloth/gemma-4-27b-it"    - 27B params, needs 40GB+ (A100)

If using 12B, also change:
  MAX_SEQ_LENGTH = 3072
  LR = 2e-4

TROUBLESHOOTING
---------------
- Error 1455 (paging file too small): Increase Windows virtual memory to 32GB+
- CUDA OOM: Reduce MAX_SEQ_LENGTH to 1024 or LORA_R to 32
- Dataset not found: Update DATASET_PATH in cell_01_config.py
- Model not found: Set load_in_4bit=True and ensure you have internet for first download

FILES NEEDED
------------
- gemma4_ayurveda_unsloth_clean.jsonl (1.69 GB, full dataset)
  OR gemma4_ayurveda_unsloth_500mb_FINAL.jsonl (404 MB, smaller subset)
- Model cache: unsloth/gemma-4-E2B-it (downloaded automatically on first run)

OUTPUT
------
- LoRA adapter saved to: E:\dataset\gemma4_ayurveda_lora_output\adapter\
- Merged model (optional): E:\dataset\gemma4_ayurveda_lora_output\merged_16bit\
