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

enable setting flags via env vars like JAX_CPU_COLLECTIVES_IMPLEMENTATION #26103

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
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
11 changes: 9 additions & 2 deletions jax/_src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -778,36 +778,43 @@ def _set(self, value: _T) -> None:

def bool_flag(name, default, *args, **kwargs) -> Flag[bool]:
update_hook = kwargs.pop("update_hook", None)
default = bool(os.getenv(name.upper(), default))
holder = Flag(name, default, update_hook)
config.add_option(name, holder, bool, args, kwargs)
return holder


def int_flag(name, default, *args, **kwargs) -> Flag[int]:
update_hook = kwargs.pop("update_hook", None)
default = int(os.getenv(name.upper(), default))
holder = Flag(name, default, update_hook)
config.add_option(name, holder, int, args, kwargs)
return holder


def float_flag(name, default, *args, **kwargs) -> Flag[float]:
update_hook = kwargs.pop("update_hook", None)
default = float(os.getenv(name.upper(), default))
holder = Flag(name, default, update_hook)
config.add_option(name, holder, float, args, kwargs)
return holder


def string_flag(name, default, *args, **kwargs) -> Flag[str]:
update_hook = kwargs.pop("update_hook", None)
default = os.getenv(name.upper(), default)
holder = Flag(name, default, update_hook)
config.add_option(name, holder, str, args, kwargs)
return holder


def enum_flag(name, default, *args, **kwargs) -> Flag[str]:
def enum_flag(name, default, enum_values, *args, **kwargs) -> Flag[str]:
update_hook = kwargs.pop("update_hook", None)
default = os.getenv(name.upper(), default)
if default not in enum_values:
raise ValueError(f"Invalid value \"{default}\" for JAX flag {name}")
holder = Flag(name, default, update_hook)
config.add_option(name, holder, 'enum', args, kwargs)
config.add_option(name, holder, 'enum', (enum_values, *args), kwargs)
return holder


Expand Down
Loading