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

Hymba multipack support #2118

Closed
wants to merge 40 commits into from
Closed
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
bb89541
lint
bursteratom Dec 2, 2024
9a00c63
lint
bursteratom Dec 2, 2024
bce29a4
trust remote code
bursteratom Dec 2, 2024
3057f8e
no smaple packing
bursteratom Dec 2, 2024
65b5c6a
flash attention false
bursteratom Dec 2, 2024
867b3b6
config
bursteratom Dec 2, 2024
ca701c5
config
bursteratom Dec 2, 2024
3bac454
test
bursteratom Dec 2, 2024
3d9afb4
test
bursteratom Dec 2, 2024
8d430d3
commenting out save_pretrained for testing
bursteratom Dec 3, 2024
5ef5cee
lint
bursteratom Dec 3, 2024
c484085
test
bursteratom Dec 3, 2024
5c01e4a
status
bursteratom Dec 3, 2024
6988c93
example
bursteratom Dec 3, 2024
4ae4ea0
removed test file
bursteratom Dec 3, 2024
c43cce6
better abstraction for has_remote_code
bursteratom Dec 3, 2024
b5f390e
misc
bursteratom Dec 3, 2024
ca47276
changed example config
bursteratom Dec 3, 2024
4e0a522
lint [skip e2e]
bursteratom Dec 4, 2024
5708b33
test [skip e2e]
bursteratom Dec 4, 2024
1e597da
test
bursteratom Dec 4, 2024
1903b36
test [skip e2e]
bursteratom Dec 4, 2024
d0bb3a5
test [skip e2e]
bursteratom Dec 4, 2024
658f68a
e2e tests for packiung + chat template for hymba [skip e2e]
bursteratom Dec 9, 2024
900dda0
lint
bursteratom Dec 9, 2024
9e520e8
lint
bursteratom Dec 9, 2024
16092ef
lint
bursteratom Dec 9, 2024
35c7189
Merge branch 'main' into hymba_multipack
bursteratom Dec 9, 2024
4c51ace
lint
bursteratom Dec 9, 2024
cf737a2
set trust_remote_Code to true for hymba testing
bursteratom Dec 9, 2024
3ed2caa
switching order of decorator
bursteratom Dec 10, 2024
8c7b305
qlora for hymba tests [skip e2e]
bursteratom Dec 10, 2024
9776154
qlora test [skip e2e]
bursteratom Dec 10, 2024
93ede0b
lint [skip e2e]
bursteratom Dec 10, 2024
b7a57a8
qlora hymba test [skip e2e]
bursteratom Dec 10, 2024
6d65df2
qlora hymba test
bursteratom Dec 10, 2024
cd7c061
separate unit test for unpacked train loss validation
bursteratom Dec 10, 2024
7078480
test
bursteratom Dec 10, 2024
209f48b
test
bursteratom Dec 10, 2024
eec782f
more test
bursteratom Dec 10, 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
58 changes: 58 additions & 0 deletions examples/hymba/fft-1.5b.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
base_model: nvidia/Hymba-1.5B-Base

load_in_8bit: false
load_in_4bit: false
strict: false

datasets:
- path: tatsu-lab/alpaca
type: alpaca
dataset_prepared_path: last_run_prepared
val_set_size: 0.05
output_dir: ./outputs/out

sequence_len: 2048
sample_packing: true
pad_to_sequence_len: true

wandb_project:
wandb_entity:
wandb_watch:
wandb_name:
wandb_log_model:

gradient_accumulation_steps: 2
micro_batch_size: 2
num_epochs: 1
optimizer: paged_adamw_8bit
lr_scheduler: cosine
learning_rate: 2e-5

train_on_inputs: false
group_by_length: false
bf16: auto
fp16:
tf32: false

trust_remote_code: true

gradient_checkpointing: true
gradient_checkpointing_kwargs:
use_reentrant: false
early_stopping_patience:
resume_from_checkpoint:
logging_steps: 1
xformers_attention:
flash_attention: true

warmup_steps: 5
evals_per_epoch: 2
eval_table_size:
saves_per_epoch: 1
debug:
deepspeed:
weight_decay: 0.0
fsdp:
fsdp_config:
special_tokens:
pad_token: <|end_of_text|>
1 change: 1 addition & 0 deletions src/axolotl/monkeypatch/multipack.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"gemmoe",
"starcoder2",
"deepseek_v2",
"hymba",
]


Expand Down
13 changes: 11 additions & 2 deletions src/axolotl/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@
from axolotl.logging_config import configure_logging
from axolotl.utils.dict import DictDefault
from axolotl.utils.freeze import freeze_layers_except
from axolotl.utils.models import load_model, load_processor, load_tokenizer
from axolotl.utils.models import (
load_model,
load_model_config,
load_processor,
load_tokenizer,
)
from axolotl.utils.trainer import setup_trainer

try:
Expand Down Expand Up @@ -145,7 +150,11 @@ def train(
os.makedirs(cfg.output_dir, exist_ok=True)
tokenizer.save_pretrained(str(Path(cfg.output_dir)))
if hasattr(model, "config"):
model.config.save_pretrained(str(Path(cfg.output_dir)))
try:
model.config.save_pretrained(str(Path(cfg.output_dir)))
except TypeError: # required to deal with Hymba in its current state
model_config = load_model_config(cfg)
model_config.save_pretrained(str(Path(cfg.output_dir)))

# In case we want to stop early with ctrl+c, this is a nice to have to save the pretrained model
if cfg.local_rank == 0:
Expand Down
16 changes: 16 additions & 0 deletions src/axolotl/utils/config/models/input/v0_4_1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1573,3 +1573,19 @@ def check_adopt_torch_version(cls, data):
"ADOPT optimizer is incompatible with torch version < 2.5.1"
)
return data

@model_validator(mode="before")
@classmethod
def check_hymba_torch_version(cls, data):
if "hymba" in data.get("base_model", {}).lower():
env_capabilities = data.get("env_capabilities", {})
torch_version = env_capabilities.get("torch_version")

if torch_version is None:
import torch

torch_version = str(torch.__version__).split("+", maxsplit=1)[0]

if version.parse(torch_version) < version.parse("2.5.0"):
raise ValueError("Hymba requires torch version >= 2.5")
return data
15 changes: 11 additions & 4 deletions src/axolotl/utils/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,10 +397,17 @@ def apply_patches(self) -> None:
and self.cfg.flash_attention
and self.cfg.sample_packing
):
has_remote_code = (
"auto_map" in self.model_config
and "AutoModelForCausalLM" in self.model_config["auto_map"]
)
# some model config objects are not subscriptable
try:
has_remote_code = (
"auto_map" in self.model_config
and "AutoModelForCausalLM" in self.model_config["auto_map"]
)
except TypeError:
has_remote_code = hasattr(
self.model_config, "auto_map"
) and "AutoModelForCausalLM" in getattr(self.model_config, "auto_map")

if has_remote_code and self.cfg.trust_remote_code is False:
# if explicitly set in the YAML, we should prefer that, for example if explicitly disabled
has_remote_code = self.cfg.trust_remote_code
Expand Down
Loading