Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions swift/ui/llm_train/llm_train.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,8 @@ def train(cls, *args):
else:
cuda_param = ''
if envs:
envs = envs.split(' ')
for env in envs:
env_list = envs.split(' ')
for env in env_list:
k, v = env.split('=')
all_envs[k] = v
Comment on lines +470 to 473
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

While this change correctly avoids shadowing the envs variable, the environment variable parsing logic can be made more robust. The current implementation has two potential issues:

  1. If there are multiple spaces between environment variable definitions (e.g., A=1 B=2), split(' ') will produce empty strings, causing a ValueError when unpacking.
  2. If an environment variable's value contains an = sign (e.g., URL=http://a.com?x=y), split('=') will produce more than two values, also causing a ValueError.

I suggest a more robust implementation that also simplifies the code by removing the intermediate env_list.

Suggested change
env_list = envs.split(' ')
for env in env_list:
k, v = env.split('=')
all_envs[k] = v
for env in envs.split(' '):
if env and '=' in env:
k, v = env.split('=', 1)
all_envs[k] = v

log_file = os.path.join(sft_args.logging_dir, 'run.log')
Expand Down
Loading