* fix: update chat_template * fix: handle gemma3 showing a lot of no content for turn 0 * fix: remove unknown config from examples * fix: test * fix: temporary disable gemma2 test * fix: stop overwriting config.text_config unnecessarily * fix: handling of set cache to the text_config section * feat: add liger gemma support and bump liger to 0.5.5 * fix: add double use_cache setting * fix: add support for final_logit_softcap in CCE for gemma2/3 * fix: set use_cache before model load * feat: add missing layernorm override * fix: handle gemma3 rmsnorm * fix: use wrapper to pass dim as hidden_size * fix: change dim to positional * fix: patch with wrong mlp * chore: refactor use_cache handling * fix import issues * fix tests.e2e.utils import --------- Co-authored-by: Wing Lian <wing@axolotl.ai>
86 lines
2.6 KiB
Python
86 lines
2.6 KiB
Python
"""
|
|
test utils for helpers and decorators
|
|
"""
|
|
|
|
import os
|
|
from functools import wraps
|
|
|
|
from huggingface_hub.utils import reset_sessions
|
|
|
|
|
|
def reload_modules(hf_hub_offline):
|
|
# Force reload of the modules that check this variable
|
|
import importlib
|
|
|
|
import datasets
|
|
import huggingface_hub.constants
|
|
|
|
# Reload the constants module first, as others depend on it
|
|
importlib.reload(huggingface_hub.constants)
|
|
huggingface_hub.constants.HF_HUB_OFFLINE = hf_hub_offline
|
|
importlib.reload(datasets.config)
|
|
setattr(datasets.config, "HF_HUB_OFFLINE", hf_hub_offline)
|
|
reset_sessions()
|
|
|
|
|
|
def enable_hf_offline(test_func):
|
|
"""
|
|
test decorator that sets HF_HUB_OFFLINE environment variable to True and restores it after the test even if the test fails.
|
|
:param test_func:
|
|
:return:
|
|
"""
|
|
|
|
@wraps(test_func)
|
|
def wrapper(*args, **kwargs):
|
|
# Save the original value of HF_HUB_OFFLINE environment variable
|
|
original_hf_offline = os.getenv("HF_HUB_OFFLINE")
|
|
|
|
# Set HF_OFFLINE environment variable to True
|
|
os.environ["HF_HUB_OFFLINE"] = "1"
|
|
|
|
reload_modules(True)
|
|
try:
|
|
# Run the test function
|
|
return test_func(*args, **kwargs)
|
|
finally:
|
|
# Restore the original value of HF_HUB_OFFLINE environment variable
|
|
if original_hf_offline is not None:
|
|
os.environ["HF_HUB_OFFLINE"] = original_hf_offline
|
|
reload_modules(bool(original_hf_offline))
|
|
else:
|
|
del os.environ["HF_HUB_OFFLINE"]
|
|
reload_modules(False)
|
|
|
|
return wrapper
|
|
|
|
|
|
def disable_hf_offline(test_func):
|
|
"""
|
|
test decorator that sets HF_HUB_OFFLINE environment variable to False and restores it after the wrapped func
|
|
:param test_func:
|
|
:return:
|
|
"""
|
|
|
|
@wraps(test_func)
|
|
def wrapper(*args, **kwargs):
|
|
# Save the original value of HF_HUB_OFFLINE environment variable
|
|
original_hf_offline = os.getenv("HF_HUB_OFFLINE")
|
|
|
|
# Set HF_OFFLINE environment variable to True
|
|
os.environ["HF_HUB_OFFLINE"] = "0"
|
|
|
|
reload_modules(False)
|
|
try:
|
|
# Run the test function
|
|
return test_func(*args, **kwargs)
|
|
finally:
|
|
# Restore the original value of HF_HUB_OFFLINE environment variable
|
|
if original_hf_offline is not None:
|
|
os.environ["HF_HUB_OFFLINE"] = original_hf_offline
|
|
reload_modules(bool(original_hf_offline))
|
|
else:
|
|
del os.environ["HF_HUB_OFFLINE"]
|
|
reload_modules(False)
|
|
|
|
return wrapper
|