Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve CI #27

Merged
merged 26 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
584bebe
Test all three configs in CI matrix
mwaskom Feb 5, 2024
4fa39ee
Minimal config updates
mwaskom Feb 5, 2024
f904f00
Run CI workflow on PRs only
mwaskom Feb 5, 2024
b0876c6
Fix CI yaml
mwaskom Feb 5, 2024
593eeed
Write the updated config back out
mwaskom Feb 5, 2024
255b2ec
Fix config read
mwaskom Feb 5, 2024
e16ed1e
Temp comment out hugginface secret
mwaskom Feb 5, 2024
700b15c
Fix data truncation
mwaskom Feb 6, 2024
233f220
Update modal environment name
mwaskom Feb 6, 2024
9f9e131
Train on more data
mwaskom Feb 6, 2024
61b6a05
Skip validation in CI
mwaskom Feb 6, 2024
ef7a35b
Nevermind, I guess we can't disable evals
mwaskom Feb 6, 2024
5f5d343
Revert changes to train / val sizes
mwaskom Feb 6, 2024
74db375
Even more val data?
mwaskom Feb 6, 2024
6a5cfa0
Fix default mistral sequence len
mwaskom Feb 6, 2024
f21f60e
Set eval steps and batch size for CI
mwaskom Feb 6, 2024
f28f503
Print some cuda diagnostics before training
mwaskom Feb 6, 2024
9798de1
Print some config / data diagnostics
mwaskom Feb 6, 2024
ef8b1f7
Don't cancel other matrix jobs one when fails
mwaskom Feb 6, 2024
737183f
Fix torch attributes
mwaskom Feb 6, 2024
231562f
Try larger mixtral micro batch size?
mwaskom Feb 6, 2024
ddb94d3
Force micro batch size
mwaskom Feb 6, 2024
9185172
Try setting eval_steps to implausibly large number
mwaskom Feb 6, 2024
009849b
Don't watch gradients in mistral; set eval_steps to default
mwaskom Feb 6, 2024
89ab93e
Try no flash attention?
mwaskom Feb 6, 2024
8046918
Smaller batch size
mwaskom Feb 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
name: CI/CD

on: workflow_dispatch
on: pull_request

jobs:
test:
environment: CI
name: Deploy
name: Test
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
config: ["codellama", "llama-2", "mistral"]
env:
MODAL_TOKEN_ID: ${{ secrets.MODAL_TOKEN_ID }}
MODAL_TOKEN_SECRET: ${{ secrets.MODAL_TOKEN_SECRET }}
MODAL_ENVIRONMENT: ci-cd
MODAL_ENVIRONMENT: CI-CD

steps:
- name: Checkout Repository
Expand All @@ -19,13 +23,20 @@ jobs:
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
python-version: "3.12"

- name: Install Modal
run: |
python -m pip install --upgrade pip
pip install modal
pip install modal pyyaml

- name: Prep config and data for CI
run: |
python ci/prep_for_ci.py --config=config/${{ matrix.config }}.yml --data=data/sqlqa.jsonl
echo `wc -l data/sqlqa.jsonl | awk '{print $1}'` lines in test data
echo Config:
cat config/${{ matrix.config }}.yml

- name: Run training job on Modal
run: |
modal run src.train --config=config/codellama.yml --data=data/sqlqa.jsonl
GPU_MEM=40 modal run src.train --config=config/${{ matrix.config }}.yml --data=data/sqlqa.jsonl
28 changes: 28 additions & 0 deletions ci/prep_for_ci.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import click
import yaml


@click.command()
@click.option("--config")
@click.option("--data")
def main(config: str, data: str):
"""Set the config for lighter-weight training and truncate the dataset."""
with open(config) as f:
cfg = yaml.safe_load(f.read())
cfg["sequence_len"] = 1024
cfg["val_set_size"] = 100
cfg["eval_batch_size"] = 2
cfg["micro_batch_size"] = 2
cfg["num_epochs"] = 2
cfg.pop("eval_steps", None)
with open(config, "w") as f:
yaml.dump(cfg, f)

with open(data) as f:
data_truncated = f.readlines()[:1000]
with open(data, "w") as f:
f.writelines(data_truncated)


if __name__ == "__main__":
main()
5 changes: 3 additions & 2 deletions config/codellama.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ tokenizer_type: CodeLlamaTokenizer
is_llama_derived_model: true

load_in_8bit: false
bf16: true
load_in_4bit: false
strict: false

datasets:
Expand All @@ -24,7 +24,7 @@ datasets:
{instruction} [/INST]

dataset_prepared_path:
val_set_size: 32 # must be at least micro_batch_size * N_GPUS, and more if eval packing.
val_set_size: 0.05
output_dir: ./lora-out

sequence_len: 4096
Expand Down Expand Up @@ -54,6 +54,7 @@ learning_rate: 0.0002

train_on_inputs: false
group_by_length: false
bf16: true
fp16: false
tf32: false

Expand Down
18 changes: 16 additions & 2 deletions config/llama-2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,28 @@ load_in_4bit: false
strict: false

datasets:
- path: mhenrichsen/alpaca_2k_test
type: alpaca
# This will be the path used for the data when it is saved to the Volume in the cloud.
- path: my_data.jsonl
ds_type: json
type:
# JSONL file contains question, context, answer fields per line.
# This gets mapped to instruction, input, output axolotl tags.
field_instruction: question
field_input: context
field_output: answer
# Format is used by axolotl to generate the prompt.
format: |-
[INST] Using the schema context below, generate a SQL query that answers the question.
{input}
{instruction} [/INST]

dataset_prepared_path:
val_set_size: 0.05
output_dir: ./lora-out

sequence_len: 4096
sample_packing: true
eval_sample_packing: false
pad_to_sequence_len: true

adapter: lora
Expand Down
12 changes: 7 additions & 5 deletions config/mistral.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ tokenizer_type: LlamaTokenizer
is_mistral_derived_model: true

load_in_8bit: false
load_in_4bit: false
strict: false

datasets:
# This will be the path used for the data when it is saved to the Volume in the cloud.
- path: my_data.jsonl
ds_type: json
type:
Expand All @@ -22,7 +24,7 @@ datasets:
{instruction} [/INST]

dataset_prepared_path:
val_set_size: 0
val_set_size: 32
output_dir: ./lora-out

sequence_len: 2048
Expand All @@ -38,13 +40,13 @@ lora_dropout: 0.05
lora_target_linear: true
lora_fan_in_fan_out:

wandb_project: mistral-7b-axolotl-train
wandb_project:
wandb_entity:
wandb_watch: gradients
wandb_watch:
wandb_run_id:

gradient_accumulation_steps: 1
micro_batch_size: 1
micro_batch_size: 16
num_epochs: 1
optimizer: adamw_bnb_8bit
lr_scheduler: cosine
Expand All @@ -62,7 +64,7 @@ resume_from_checkpoint:
local_rank:
logging_steps: 1
xformers_attention:
flash_attention: true
flash_attention: false

warmup_steps: 10
save_steps:
Expand Down
17 changes: 8 additions & 9 deletions src/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,16 @@
.env(dict(HUGGINGFACE_HUB_CACHE="/pretrained", HF_HUB_ENABLE_HF_TRANSFER="1"))
)

vllm_image = (
Image.from_registry("nvidia/cuda:12.1.0-base-ubuntu22.04", add_python="3.10")
.pip_install(
"vllm==0.2.5",
"torch==2.1.2",
"torchvision==0.16.2",
"torchaudio==2.1.2"
)
vllm_image = Image.from_registry(
"nvidia/cuda:12.1.0-base-ubuntu22.04", add_python="3.10"
).pip_install(
"vllm==0.2.5",
"torch==2.1.2",
"torchvision==0.16.2",
"torchaudio==2.1.2",
)

stub = Stub(APP_NAME, secrets=[Secret.from_name("huggingface")])
stub = Stub(APP_NAME) # , secrets=[Secret.from_name("huggingface")])

# Volumes for pre-trained models and training runs.
pretrained_volume = Volume.persisted("example-pretrained-vol")
Expand Down
5 changes: 4 additions & 1 deletion src/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ def run_cmd(cmd: str, run_folder: str):
_allow_background_volume_commits=True,
)
def train(run_folder: str):
print(f"Starting training run in {run_folder}")
import torch

print(f"Starting training run in {run_folder}.")
print(f"Using {torch.cuda.device_count()} {torch.cuda.get_device_name()} GPU(s).")

TRAIN_CMD = "accelerate launch -m axolotl.cli.train ./config.yml"
run_cmd(TRAIN_CMD, run_folder)
Expand Down