dragon.ai.inference.llm_engine.find_free_port

find_free_port(device_index: int = 0, base_port=20000, port_range_size=10000) str [source]

Return an available TCP port using the worker’s device index as seed.

The device index seeds a deterministic random starting point within the range, so concurrent workers on the same node begin scanning from widely separated ports, virtually eliminating collisions. If a port is taken, the search wraps around until a free one is found.

The default range (20000-29999) is intentionally disjoint from the vLLM get_open_port() patch range (30000-60000) so the two never interfere.

Parameters:
  • device_index (int ) – GPU device index used to seed the random start.

  • base_port (int ) – Starting port of the search range.

  • port_range_size (int ) – Size of the port range to scan.

Raises:

IOError – If no free port is found in the range.

Returns:

A free port as a string.

Return type:

str