unilab.base.process_device.resolve_backend_env_device_id

unilab.base.process_device.resolve_backend_env_device_id(backend_type, *, devices=None, rank=0, local_rank=None, world_size=1, learner_device=None)[source]

Resolve the integer simulator device id for a training rank.

Parameters:
  • backend_type (str) – Selected UniSim backend.

  • devices (Sequence[int] | None) – training.devices in the host-visible namespace. This is used by the off-policy launcher and by single-process PPO.

  • rank (int) – Off-policy data-parallel rank (rank zero by default).

  • local_rank (int | None) – LOCAL_RANK from torchrun. In a distributed PPO worker this is the logical index inside the launcher’s remapped CUDA_VISIBLE_DEVICES list.

  • world_size (int) – Torchrun world size. Values greater than one select the local_rank namespace; values of one select devices[rank].

  • learner_device (str | None) – Explicit learner device fallback when no topology was configured (for example APPO or a single-device play command).

Return type:

int | None

Returns None for backends without an explicit simulator device field. For a torchrun worker the returned id is intentionally local (rather than the host index in devices), because the worker subprocess inherits the remapped CUDA_VISIBLE_DEVICES environment.