-
Notifications
You must be signed in to change notification settings - Fork 327
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement ring attention primative for Jax.
Signed-off-by: Michael Goldfarb <mgoldfarb@nvidia.com> Signed-off-by: Ming Huang <mingh@nvidia.com>
- Loading branch information
1 parent
e5ffaa7
commit ad91add
Showing
8 changed files
with
701 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Copyright (c) 2022-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
# | ||
# See LICENSE for license information. | ||
|
||
import pytest | ||
from functools import partial | ||
import os | ||
|
||
from transformer_engine.jax.cpp_extensions.misc import get_xla_flag | ||
|
||
|
||
@pytest.fixture(autouse=True, scope="function") | ||
def preserve_xla_flags(): | ||
"""Ensures the XLA flags environment variable is restored after any tests in this file run.""" | ||
old_flags = os.getenv("XLA_FLAGS") | ||
yield | ||
if old_flags is not None: | ||
os.environ["XLA_FLAGS"] = old_flags | ||
|
||
|
||
def test_get_xla_flag(request): | ||
os.environ["XLA_FLAGS"] = "" | ||
assert get_xla_flag("") is None | ||
assert get_xla_flag("--foo") is None | ||
assert get_xla_flag("--bar=1") is None | ||
|
||
os.environ["XLA_FLAGS"] = "--foo --bar=1 --baz=biz" | ||
assert get_xla_flag("--foo") == True | ||
assert get_xla_flag("--bar") == "1" | ||
assert get_xla_flag("--bar", cast=int) == 1 | ||
assert get_xla_flag("--bar", cast=bool) == True | ||
assert get_xla_flag("--baz") == "biz" | ||
with pytest.raises(ValueError): | ||
# cast will fail | ||
assert get_xla_flag("--baz", cast=int) | ||
assert get_xla_flag("--xla") is None | ||
|
||
os.environ["XLA_FLAGS"] = "--xla_abc --xla_abb" | ||
assert get_xla_flag("--xla_abc") == True | ||
assert get_xla_flag("--xla_abb") == True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.