unsloth/tests/utils
Taranum Wasu 68dfaf8389 fix(attn-mask-compat): fall back when transformers < 4.52 lacks is_tracing
The compat module imports `is_tracing` from
`transformers.utils.import_utils`, but that symbol is only exported
from transformers >= 4.52 (added when the upstream
`_prepare_4d_attention_mask_for_sdpa` rewrite landed). Unsloth
declares `transformers>=4.51.3` in pyproject.toml, so on the lower
bound tested by CI (`__from_pyproject__` matrix cell) the new
top-level import raises ImportError before any patched module can
import the compat helpers.

Mirror the conservative pre-`is_tracing` upstream behavior: when the
symbol is missing, define a local `is_tracing(tensor=None)` that only
consults `is_torchdynamo_compiling`. The `tensor` argument is accepted
but ignored — the older release has no public API for fake-tensor /
JAX-jit detection via `import_utils` either, and the previously-used
upstream code path on transformers 4.51.x guarded the same checks by
`is_torchdynamo_compiling` alone.

Tests:
- `test_import_falls_back_when_is_tracing_missing` reloads the compat
  module with `is_tracing` removed from
  `transformers.utils.import_utils` and asserts the local fallback is
  in use (returns False when dynamo is idle, accepts the optional
  tensor positional arg).
- All 26 tests in `tests/utils/test_attn_mask_compat.py` pass.

This addresses the Codex review feedback (P1) on PR #6880.

Signed-off-by: Taranum Wasu <taranumwasu@Taranums-MacBook-Pro.local>
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-08 03:36:47 +05:30
..
__init__.py Revert "[FIX] Vllm guided decoding params (#3662)" 2025-12-01 05:43:45 -08:00
aime_eval.md reroute merge logic language models + comprehensive tests + eval kits (#2673) 2025-06-02 20:32:57 -07:00
aime_eval.py Reduce and tighten comments and docstrings across the test suite (#6429) 2026-06-18 01:07:09 -07:00
cleanup_utils.py Reduce and tighten comments and docstrings across the test suite (#6429) 2026-06-18 01:07:09 -07:00
data_utils.py Reduce and tighten comments and docstrings across the test suite (#6429) 2026-06-18 01:07:09 -07:00
generate_dataset_with_none.py Reduce and tighten comments and docstrings across the test suite (#6429) 2026-06-18 01:07:09 -07:00
hf_utils.py Reduce and tighten comments and docstrings across the test suite (#6429) 2026-06-18 01:07:09 -07:00
ocr_eval.md Fix Typos in Documentation and Comments (#2721) 2025-06-17 04:34:51 -07:00
ocr_eval.py Reduce and tighten comments and docstrings across the test suite (#6429) 2026-06-18 01:07:09 -07:00
os_utils.py Reduce and tighten comments and docstrings across the test suite (#6429) 2026-06-18 01:07:09 -07:00
perplexity_eval.md reroute merge logic language models + comprehensive tests + eval kits (#2673) 2025-06-02 20:32:57 -07:00
perplexity_eval.py Reduce and tighten comments and docstrings across the test suite (#6429) 2026-06-18 01:07:09 -07:00
run_none_detect_tests.py Reduce and tighten comments and docstrings across the test suite (#6429) 2026-06-18 01:07:09 -07:00
test_attention_dispatch_dora_dtype.py Fix FlashAttention fp32 crash with DoRA (use_dora=True) (#6526) 2026-06-23 01:29:19 -07:00
test_attention_masks.py Formatting: ruff line-length 100, kwarg-spacing passes, drop blank after short local imports (#6079) 2026-06-08 04:24:13 -07:00
test_attn_mask_compat.py fix(attn-mask-compat): fall back when transformers < 4.52 lacks is_tracing 2026-07-08 03:36:47 +05:30
test_batched_leftpad_generation_gpu.py Reduce and tighten comments and docstrings across the test suite (#6429) 2026-06-18 01:07:09 -07:00
test_packing.py Reduce and tighten comments and docstrings across the test suite (#6429) 2026-06-18 01:07:09 -07:00
test_prepare_inputs_leftpad.py Reduce and tighten comments and docstrings across the test suite (#6429) 2026-06-18 01:07:09 -07:00
test_q_galore.py Reduce and tighten comments and docstrings across the test suite (#6429) 2026-06-18 01:07:09 -07:00
test_qat.py Reduce and tighten comments and docstrings across the test suite (#6429) 2026-06-18 01:07:09 -07:00
test_rope_scaling_drift.py Reduce and tighten comments and docstrings across the test suite (#6429) 2026-06-18 01:07:09 -07:00
test_trunc_normal_patch.py Reduce and tighten comments and docstrings across the test suite (#6429) 2026-06-18 01:07:09 -07:00