Skip to content

Commit 35bc8bd

Browse files
authored
[Misc] Copy HF_TOKEN env var to Ray workers (#21406)
Signed-off-by: Rui Qiao <[email protected]>
1 parent 4594fc3 commit 35bc8bd

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

vllm/executor/ray_distributed_executor.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ class RayDistributedExecutor(DistributedExecutorBase):
5858
"VLLM_HOST_IP", "VLLM_HOST_PORT", "LOCAL_RANK", "CUDA_VISIBLE_DEVICES"
5959
}
6060

61+
# These non-vLLM env vars are copied from the driver to workers
62+
ADDITIONAL_ENV_VARS = {"HF_TOKEN", "HUGGING_FACE_HUB_TOKEN"}
63+
6164
uses_ray: bool = True
6265

6366
def _init_executor(self) -> None:
@@ -326,7 +329,8 @@ def sort_by_driver_then_worker_ip(item: RayWorkerMetaData):
326329
# Environment variables to copy from driver to workers
327330
env_vars_to_copy = get_env_vars_to_copy(
328331
exclude_vars=self.WORKER_SPECIFIC_ENV_VARS,
329-
additional_vars=set(current_platform.additional_env_vars),
332+
additional_vars=set(current_platform.additional_env_vars).union(
333+
self.ADDITIONAL_ENV_VARS),
330334
destination="workers")
331335

332336
# Copy existing env vars to each worker's args

vllm/ray/ray_env.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ def get_env_vars_to_copy(exclude_vars: Optional[set[str]] = None,
4343
exclude_vars: A set of vllm defined environment variables to exclude
4444
from copying.
4545
additional_vars: A set of additional environment variables to copy.
46+
If a variable is in both exclude_vars and additional_vars, it will
47+
be excluded.
4648
destination: The destination of the environment variables.
4749
Returns:
4850
A set of environment variables to copy.
@@ -52,10 +54,9 @@ def get_env_vars_to_copy(exclude_vars: Optional[set[str]] = None,
5254

5355
env_vars_to_copy = {
5456
v
55-
for v in envs.environment_variables
57+
for v in set(envs.environment_variables).union(additional_vars)
5658
if v not in exclude_vars and v not in RAY_NON_CARRY_OVER_ENV_VARS
5759
}
58-
env_vars_to_copy.update(additional_vars)
5960

6061
to_destination = " to " + destination if destination is not None else ""
6162

0 commit comments

Comments
 (0)