Skip to content

Commit

Permalink
Enable or disable bf16 support based on availability (#1116)
Browse files Browse the repository at this point in the history
  • Loading branch information
simhallq committed Jan 14, 2024
1 parent 2202a20 commit 0865613
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/axolotl/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ def normalize_config(cfg):
cfg.device_map = {"": int(os.environ.get("LOCAL_RANK", 0))}
cfg.batch_size = cfg.batch_size * cfg.world_size

if cfg.bf16 == "auto":
if is_torch_bf16_gpu_available():
LOG.debug("bf16 support detected, enabling for this configuration.")
cfg.bf16 = True
else:
LOG.debug("bf16 support not detected, disabling for this configuration.")
cfg.bf16 = False

if cfg.device == "mps":
cfg.load_in_8bit = False
cfg.tf32 = False
Expand Down
21 changes: 21 additions & 0 deletions tests/test_normalize_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Test classes for checking functionality of the cfg normalization
"""
import unittest
from unittest.mock import patch

from axolotl.utils.config import normalize_cfg_datasets, normalize_config
from axolotl.utils.dict import DictDefault
Expand Down Expand Up @@ -67,3 +68,23 @@ def test_chat_template_chatml(self):

assert cfg.datasets[0].conversation == "vicuna_v1.1"
assert cfg.datasets[1].conversation == "chatml"

@patch("axolotl.utils.config.is_torch_bf16_gpu_available")
def test_bf16_auto_setter_available(self, mock_bf16_avail):
cfg = self._get_base_cfg()
cfg.bf16 = "auto"
mock_bf16_avail.return_value = True

normalize_config(cfg)

self.assertTrue(cfg.bf16)

@patch("axolotl.utils.config.is_torch_bf16_gpu_available")
def test_bf16_auto_setter_not_available(self, mock_bf16_avail):
cfg = self._get_base_cfg()
cfg.bf16 = "auto"
mock_bf16_avail.return_value = False

normalize_config(cfg)

self.assertFalse(cfg.bf16)

0 comments on commit 0865613

Please sign in to comment.