Expand description
Cluster-mode env preparation. fdl-cli sets FLODL_INTERNAL_FULL_CLUSTER_JSON
FLODL_INTERNAL_FDL_CMD+FDL_ENVon its process env so the user binary inherits them and detects launcher role viaflodl::distributed::launcher::dispatch. Fan-out, log fan-in, and ClusterController all live on the flodl side. Entry pointcluster::prepare_cluster_env; recursion guard viacluster::should_dispatch. Cluster-mode env preparation.
Process-per-rank model: flodl owns fan-out and controller
orchestration (flodl::distributed::launcher::run_launcher). fdl-cli’s
job here is purely to ship the parsed cluster topology to the launcher
via env vars, then let the normal RunScript / ExecCommand dispatch
invoke the user binary. The user binary’s
flodl::distributed::launcher::dispatch reads the env, detects
launcher role, and fans out (ssh for remote hosts, fork+exec for local
hosts). All log fan-in + ClusterController + exit-code propagation happen on
the flodl side.
fdl @cluster train
↓ fdl-cli parses fdl.yml + fdl.cluster.yml overlay
↓ fdl-cli calls prepare_cluster_env: sets FLODL_INTERNAL_FULL_CLUSTER_JSON,
FLODL_INTERNAL_FDL_CMD, FDL_ENV on its own process env
↓ fdl-cli falls through to normal RunScript / ExecCommand path
↓ resolved command (e.g. `cargo run --release --bin my-trainer`) runs
↓ my-trainer inherits env, flodl::launcher::dispatch detects Launcher
↓ launcher fans out: ssh per remote host, fork+exec per local rank
↓ each rank child has FLODL_INTERNAL_CLUSTER_JSON + FLODL_INTERNAL_LOCAL_RANK set
↓ rank-side flodl::launcher::dispatch returns Role::Rank, training runsRecursion guard: the launcher’s ssh fan-out invokes fdl <cmd> on the
remote, which re-enters fdl-cli with FLODL_INTERNAL_CLUSTER_JSON set (not
FLODL_INTERNAL_FULL_CLUSTER_JSON). should_dispatch
returns false in that case so the remote fdl-cli skips cluster setup
and just runs the user binary normally — the user binary’s launcher
dispatch then detects Role::Rank (because FLODL_INTERNAL_LOCAL_RANK is also
set).
Constants§
- ENV_
CLUSTER_ EXTRA_ HOSTS - Pre-resolved
name:ippairs (space-separated) for every cluster host, written byprepare_cluster_envusing the controller’s NSS resolution. Consumed by run/prebuild/schema-cache when they builddocker compose run --rmcommands: each pair is injected as a--add-host name:ipflag so the containerized launcher can SSH into cluster hosts without depending on the container’s own resolver (which lackslibnss-libvirtetc.). - ENV_
CLUSTER_ JSON - Env var name carrying the slim per-rank envelope. Set by the
launcher (not fdl-cli) on each rank child. Kept here so the
recursion guard can reference it by name. Mirrors
flodl::distributed::cluster::ENV_CLUSTER_JSON. - ENV_
FDL_ CMD - Env var name carrying the original fdl command name (e.g.
train). Read by the launcher when it needs to invokefdl <cmd>over ssh on remote hosts. Mirrorsflodl::distributed::launcher::ENV_FDL_CMD. - ENV_
FDL_ ENV - Env var name picking the overlay env name (e.g.
cluster). Set by fdl-cli at env-selector parsing time; propagated through to remote hosts by the launcher so they see the same overlay-merged view. - ENV_
FULL_ CLUSTER_ JSON - Env var name carrying the full multi-host topology (hex-encoded
JSON of
ClusterConfig). Set by fdl-cli on its own process env so the spawned user binary inherits it and detects launcher role. Mirrorsflodl::distributed::launcher::ENV_FULL_CLUSTER_JSON. - ENV_
HOST_ OVERRIDE - Env var name overriding the OS hostname for cluster lookups.
Mirrors
flodl::distributed::cluster::ENV_HOST_OVERRIDE. - ENV_
HOST_ USER - Controller’s OS user name (resolved on the host by fdl-cli, before
any docker spawn). The launcher in the container reads it as the
default
ssh -ltarget when the per-hostssh.user:is unset. Bridges the container-vs-host user mismatch (containers ship a stockubuntuUID-1000 user, butubuntu@<remote>is rarely the account the user actually uses on cluster hosts). - ENV_
LOCAL_ RANK - Env var name picking this rank’s local-rank index within its host.
Set by the launcher on rank children. Mirrors
flodl::distributed::cluster::ENV_LOCAL_RANK. - ENV_
NET_ TIMEOUT_ SCALE - Env var scaling every flodl cluster network deadline together
(connect budget, write-stall, heartbeat staleness, coord-liveness,
CPU reduce read). Mirrors
flodl::distributed::wire’s constant + validation rule (kept in lockstep — flodl-cli is decoupled from the library crate). The library reader warns-and-defaults on a bad value; the cluster fan-out path callsvalidate_net_timeout_scalefirst so an explicit-but-invalid value errors loudly BEFORE any host is touched.
Functions§
- cluster_
compose_ overlay_ arg - Write a temporary docker-compose overlay (under
project_root) that populatesextra_hosts:for the cluster-capable services (cuda,dev,bench) from the controller-resolved cluster hosts inENV_CLUSTER_EXTRA_HOSTS, then return the-fflag sequence to splice in front ofdocker compose run. - hex_
encode - Hex-encode raw bytes (lowercase, no separators). Companion to the
library’s
hex_decodeinflodl::distributed::cluster. Kept here soprepare_cluster_envdoesn’t pull in a flodl runtime dep. - is_
recursive_ invocation - Whether this fdl invocation is itself a spawned child of a launcher’s
ssh fan-out (
FLODL_INTERNAL_CLUSTER_JSONalready set in env). Used as the recursion guard everywhere cluster dispatch is evaluated. - is_
reserved_ cluster_ env_ key - True if
keymust not appear in a user-supplied cluster/hostenvmap. Mirrorsflodl::distributed::cluster::is_reserved_cluster_env_key(kept in lockstep — flodl-cli is decoupled from the library crate, so the reserved rule is duplicated, not imported). The launcher applies user env after its own built-ins (shell last-wins), so a launcher- owned key set via env would silently override device mapping / rank identity / the HMAC envelope. Reserved: the loudFLODL_INTERNAL_prefix (all launcher-private vars, future-proof) plus three names that are user-facing elsewhere but launcher-owned per-rank here (CUDA_VISIBLE_DEVICES+CUDA_DEVICE_ORDER,ENV_HOST_OVERRIDE,ENV_FDL_ENV). User-facing knobs (FLODL_VERBOSITY,FLODL_DASHBOARD_BIND, NCCL tuning,LD_LIBRARY_PATH) are deliberately allowed. - prepare_
cluster_ env - Prepare the env vars needed for the user binary’s flodl launcher to
detect launcher role and fan out. Caller continues to normal
dispatch (
RunScript/ExecCommand); the spawned subprocess inherits these env vars and the launcher takes over. - prepare_
test_ cluster_ env - Prepare the testing-cluster envelope (
FLODL_TESTING_CLUSTER_JSON). - resolve_
local_ hostname - Resolve the local OS hostname. Used by
gpus::synthesize_local_cluster(the--gpussingle-host shorthand) and byprebuildto skip the controller from the remote-host fan-out. Test/override seam viaENV_HOST_OVERRIDE; falls back to thehostname(1)command. - resolve_
local_ user - Resolve the controller’s OS user name. Used to pre-populate
ENV_HOST_USERbefore docker spawn, so the launcher inside the container can defaultssh -l <user>to the host’s identity. Falls throughUSERthenwhoami;Nonewhen both fail — the caller then leavesENV_HOST_USERunset and the launcher omits-lentirely, so ssh applies its own defaults (ssh_config Userdirectives, the effective uid). Never fabricate a name: a made-up-l unknown-userproduced a bare “Permission denied (publickey)” with no hint the username was invented. - should_
dispatch - Top-level cluster-dispatch decision.
- validate_
net_ timeout_ scale - Validate
FLODL_NET_TIMEOUT_SCALEfrom the process env: unset is fine (scale 1.0); a set value must parse as a finite float ≥ 0.1. Mirrors the library’s parse rule.