[RFC] Unify device configuration across collectors, evaluators, and the inference server
Context
#3893 introduced InferenceDeviceConfig, a dataclass grouping the four devices
involved in asynchronous policy-server collection (policy_device,
output_device, env_device, storing_device), consumed by
InferenceServer, ProcessInferenceServer, and AsyncBatchedCollector.
Review of that PR raised design questions that were deliberately deferred so the stack could land (the PR itself only received mechanical fixes: sentinel-based mutual-exclusivity checks, documented/rejected unused fields, stronger device tests):
- Scope. Regular collectors (
Collector,MultiCollector, batched variants) and evaluators expose the same concepts as loose kwargs (device,policy_device,env_device,storing_device, plusno_cuda_syncetc.). If a structured device config is the right API, it should not be exclusive to the inference-server path -- otherwise we grow two parallel conventions. - Deprecation story. If collectors adopt
device_config, do we softly deprecate the explicit device kwargs? That touches a very wide public surface and needs the standard two-minor-release cycle withFutureWarnings naming the target version. - Multi-collector semantics. Collectors with sub-collectors accept
per-worker device lists today. Should they take a
list[InferenceDeviceConfig](one per worker), a single config broadcast to all workers, or both? - API bloat. The concern is that config objects only pay off if they
replace boilerplate rather than adding a second way to say the same
thing. A decision is needed on whether
InferenceServerConfig/InferenceDeviceConfigbecome the canonical convention (with kwargs as thin sugar), or stay an inference-server-local convenience. - Interaction with Hydra configs.
torchrl/trainers/algorithms/configs/already defines Hydra dataclasses for collectors. If runtime config objects and Hydra configs coexist, the mapping between them should be mechanical (field names and defaults aligned) to keep rule-14 parity cheap.
Proposal sketch (to be debated)
- Promote
InferenceDeviceConfigtotorchrl.collectors(re-exported fromtorchrl.modules.inference_serverfor BC) and rename or alias itDevicePlacementConfig. - Accept
device_configonCollector/MultiCollector/ evaluator constructors; single config broadcasts,Sequence[DevicePlacementConfig]maps per worker. - Keep explicit kwargs working for at least two minor releases; emit
FutureWarningonly once a decision on final removal is made. - One resolution function shared by all consumers so precedence rules
(
devicealias,env_devicefallback foroutput_device, etc.) are defined in exactly one place.
Non-goals
- Changing runtime semantics of any device transfer.
- Touching the Hydra config tree beyond keeping field parity.
@vmoens I agree on the shared resolution function, and I think that part could ship now as a plain refactor regardless of the promotion. For the rest, I think the deprecation question should be settled first, because the promotion only makes sense if the config becomes the canonical representation;otherwise we're just maintaining two spellings of the same thing.