const.py 869 B

12345678910111213141516171819202122232425262728293031323334
  1. """
  2. Constants.
  3. Contains constants used to setup collective groups.
  4. """
  5. import hashlib
  6. import os
  7. from enum import Enum, auto
  8. def get_store_name(group_name):
  9. """Generate the unique name for the NCCLUniqueID store (named actor).
  10. Args:
  11. group_name: unique user name for the store.
  12. Return:
  13. str: SHA256-hexlified name for the store.
  14. """
  15. if not group_name:
  16. raise ValueError("group_name is None.")
  17. hexlified_name = hashlib.sha256(group_name.encode()).hexdigest()
  18. return hexlified_name
  19. class ENV(Enum):
  20. """ray.util.collective environment variables."""
  21. NCCL_USE_MULTISTREAM = auto(), lambda v: (v or "True") == "True"
  22. @property
  23. def val(self):
  24. """Return the output of the lambda against the system's env value."""
  25. _, default_fn = self.value
  26. return default_fn(os.getenv(self.name))