|
Download README.md from Ai2Web3/calm2-7b-chat: direct link, hf CLI and curl.
- Browser
- Download file 5.26 kB
-
https://huggingface.co/Ai2Web3/calm2-7b-chat/resolve/main/README.md
- Command line
-
hf download hf://Ai2Web3/calm2-7b-chat/README.md
-
curl -L -o README.md https://huggingface.co/Ai2Web3/calm2-7b-chat/resolve/main/README.md
5.26 kB
| # Fine-Tuned CALM2-7B-Chat on Hawaii Wildfires Data | |
| ## Model Description | |
| This is a fine-tuned version of [cyberagent/calm2-7b-chat](https://huggingface.co/cyberagent/calm2-7b-chat), a 7B parameter Transformer-based language model designed for dialogue use cases, supporting both Japanese and English. The fine-tuning incorporates specific knowledge about the August 2023 Hawaii wildfires, sourced from the Maui Police Department's report. The goal is to enhance the model's ability to respond to queries related to this event in a conversational manner. | |
| The fine-tuning was performed using QLoRA (4-bit quantization) and LoRA adapters to efficiently adapt the model on limited hardware, such as Google Colab's free T4 GPU. | |
| ## Authors | |
| - Base Model: CyberAgent | |
| - Fine-Tuning: Ai2Web3(LogeswaranA)/PradeepNatarajan (GitHub/Hugging Face username) | |
| ## Intended Uses | |
| - **Primary Use**: Chatbot or dialogue systems that need factual information about the 2023 Hawaii wildfires. | |
| - **Out-of-Scope Uses**: Not intended for generating harmful content, misinformation, or applications requiring high-stakes decision-making without human oversight. | |
| ## Training Data | |
| The dataset consists of raw text extracted from the Maui Police Department's preliminary after-action report on the August 2023 Hawaii wildfires. The report is available at: [http://www.mauipolice.com/uploads/1/3/1/2/131209824/pre_aar_master_copy_final_draft_1.23.24.pdf](http://www.mauipolice.com/uploads/1/3/1/2/131209824/pre_aar_master_copy_final_draft_1.23.24.pdf). | |
| Specific files used: | |
| - `hawaii_wf_4.txt` | |
| - `hawaii_wf_2.txt` | |
| These files contain unformatted text copied from the PDF, focusing on details like incident response, timelines, and observations from the wildfires. | |
| The dataset was loaded using Hugging Face's `datasets` library as a text dataset. | |
| ## Training Procedure | |
| ### Preprocessing | |
| - Tokenizer: From the base model (`cyberagent/calm2-7b-chat`), with PAD token added as EOS if missing. | |
| - Data Tokenization: Each text sample was tokenized without additional formatting. | |
| ### Fine-Tuning Details | |
| - **Quantization**: 4-bit using BitsAndBytes with double quantization, NF4 type, and bfloat16 compute dtype. | |
| - **LoRA Configuration**: | |
| - Rank (`r`): 8 | |
| - Alpha: 64 | |
| - Target Modules: `["q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj"]` | |
| - Dropout: 0.05 | |
| - Bias: None | |
| - Task Type: CAUSAL_LM | |
| - **Trainer Settings** (using Hugging Face Transformers): | |
| - Batch Size: 2 (per device) | |
| - Gradient Accumulation Steps: 2 | |
| - Epochs: 3 (but limited to max_steps=20) | |
| - Learning Rate: 1e-4 | |
| - Optimizer: paged_adamw_8bit | |
| - Logging Steps: 10 | |
| - Save Strategy: Epoch (with save_steps=50) | |
| - Data Collator: For language modeling (mlm=False) | |
| - **Hardware**: Trained on Google Colab with GPU (NVIDIA T4). | |
| - Gradient checkpointing was enabled for memory efficiency. | |
| The model was prepared for k-bit training and used PEFT for LoRA integration. | |
| ## Evaluation | |
| No formal evaluation was performed in the training script. Qualitative testing via inference is recommended to assess performance on wildfire-related queries. | |
| ## Usage | |
| To load and use the fine-tuned model with PEFT: | |
| ```python | |
| from peft import PeftModel | |
| from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig | |
| import torch | |
| base_model_id = "cyberagent/calm2-7b-chat" | |
| repo_id = "Ai2Web3/calm2-7b-chat" | |
| # Define the same quantization config as used during training | |
| bnb_config = BitsAndBytesConfig( | |
| load_in_4bit=True, | |
| bnb_4bit_use_double_quant=True, | |
| bnb_4bit_quant_type="nf4", | |
| bnb_4bit_compute_dtype=torch.bfloat16 | |
| ) | |
| # Load base model with quantization, forcing all to GPU (assuming it fits) | |
| model = AutoModelForCausalLM.from_pretrained( | |
| base_model_id, | |
| quantization_config=bnb_config, | |
| device_map={"": "cuda:0"} # Force everything to GPU 0; change if multi-GPU | |
| ) | |
| tokenizer = AutoTokenizer.from_pretrained(base_model_id) | |
| # Load LoRA adapters (adapters will follow the base model's device map) | |
| model = PeftModel.from_pretrained(model, repo_id) | |
| # Inference example | |
| prompt = "What caused the Hawaii wildfires in August 2023?" | |
| inputs = tokenizer(prompt, return_tensors="pt").to(model.device) | |
| outputs = model.generate(**inputs, max_new_tokens=200) | |
| print(tokenizer.decode(outputs[0], skip_special_tokens=True)) | |
| ``` | |
| For quantized inference, apply the same BitsAndBytesConfig as during training.Limitations and BiasesTraining Scale: Limited to 20 steps on a small dataset, which may result in incomplete adaptation or overfitting. | |
| Language: Base model supports Japanese and English; fine-tuning data is in English, so performance may vary for Japanese queries. | |
| Biases: Inherits biases from the base model and training data, which is an official report and may reflect institutional perspectives. | |
| Hallucinations: As with all LLMs, the model may generate inaccurate information; verify outputs against reliable sources. | |
| Safety: Not tested for harmful outputs; use with caution. | |
| License | |
| This model is licensed under Apache-2.0, following the base model's license. | |
| Acknowledgments Base model by CyberAgent. | |
| Tutorial and data preparation inspired by poloclub/Fine-tuning-LLMs. | |
| Fine-tuning powered by Hugging Face Transformers, PEFT, and BitsAndBytes. | |