Skip to content

Conversation

@saurabhkoshatwar
Copy link
Contributor

@saurabhkoshatwar saurabhkoshatwar commented Feb 22, 2025

Resolves #6997

This PR conditionally quotes environment variable values—only wrapping those containing special characters (like parentheses) that could trigger bash errors. Safe values remain unquoted.

@saurabhkoshatwar saurabhkoshatwar changed the title conditionally quote env vars Conditionally quote env vars Feb 22, 2025
@saurabhkoshatwar saurabhkoshatwar marked this pull request as draft February 22, 2025 20:29
@saurabhkoshatwar saurabhkoshatwar marked this pull request as ready for review February 22, 2025 21:05
@loadams loadams self-assigned this Feb 24, 2025
@qiuosier
Copy link

qiuosier commented Feb 25, 2025

This fix avoided some errors. However, there is still error with variable containing double quotes.
For example, when the var is a valid JSON string,

var = "{\"a\": \"b\"}"

after quoting, it will become

"{"a": "b"}"

then, in bash

export var="{"a": "b"}"

will export the var as

{a: b}

which is no longer a valid JSON string.

Shall we use shlex.quote() instead?

@saurabhkoshatwar
Copy link
Contributor Author

@loadams cpu-torch-latest ci stuck, please rerun

@tjruwase
Copy link
Contributor

tjruwase commented Mar 1, 2025

@saurabhkoshatwar, thanks for the PR. Is it possible to add a unit test here?
https://github.com/deepspeedai/DeepSpeed/blob/master/tests/unit/launcher/test_user_args.py

Signed-off-by: Saurabh <saurabhkoshatwar1996@gmail.com>
Signed-off-by: Saurabh <saurabhkoshatwar1996@gmail.com>
@saurabhkoshatwar
Copy link
Contributor Author

cc @loadams @tjruwase

@loadams
Copy link
Collaborator

loadams commented Mar 11, 2025

cc @loadams @tjruwase

Thanks @saurabhkoshatwar, will review. Curious on your thoughts on @qiuosier's comment?

Also can you take a look at the formatting errors?

@loadams
Copy link
Collaborator

loadams commented Mar 14, 2025

This fix avoided some errors. However, there is still error with variable containing double quotes. For example, when the var is a valid JSON string,

var = "{\"a\": \"b\"}"

after quoting, it will become

"{"a": "b"}"

then, in bash

export var="{"a": "b"}"

will export the var as

{a: b}

which is no longer a valid JSON string.

Shall we use shlex.quote() instead?

@qiuosier - would you be willing to submit a PR with a suggestion for resolving this? Also do you have a use case where an envvar is a json string that we can add as a test case? Or would you be willing to open an issue for this?

@saurabhkoshatwar
Copy link
Contributor Author

cc @loadams @tjruwase

Thanks @saurabhkoshatwar, will review. Curious on your thoughts on @qiuosier's comment?

Also can you take a look at the formatting errors?

I’m also curious about the use case where an envvar is a JSON string. @qiuosier, please share—I can update it in this PR.

@tjruwase
Copy link
Contributor

I’m also curious about the use case where an envvar is a JSON string. @qiuosier, please share—I can update it in this PR.

@saurabhkoshatwar, I think it is fine for additional features to come through a separate PR. I feel this PR provides enough benefits as is.

@tjruwase tjruwase added this pull request to the merge queue Mar 17, 2025
Merged via the queue into deepspeedai:master with commit 591d4d4 Mar 17, 2025
10 checks passed
mauryaavinash95 pushed a commit to DataStates/DeepSpeed that referenced this pull request Mar 20, 2025
Resolves deepspeedai#6997 

This PR conditionally quotes environment variable values—only wrapping
those containing special characters (like parentheses) that could
trigger bash errors. Safe values remain unquoted.

---------

Signed-off-by: Saurabh <saurabhkoshatwar1996@gmail.com>
Signed-off-by: Saurabh Koshatwar <saurabhkoshatwar1996@gmail.com>
Co-authored-by: Logan Adams <114770087+loadams@users.noreply.github.com>
loadams added a commit that referenced this pull request Mar 25, 2025
Resolves #6997 

This PR conditionally quotes environment variable values—only wrapping
those containing special characters (like parentheses) that could
trigger bash errors. Safe values remain unquoted.

---------

Signed-off-by: Saurabh <saurabhkoshatwar1996@gmail.com>
Signed-off-by: Saurabh Koshatwar <saurabhkoshatwar1996@gmail.com>
Co-authored-by: Logan Adams <114770087+loadams@users.noreply.github.com>
Signed-off-by: Logan Adams <loadams@microsoft.com>
ys950902 pushed a commit to ys950902/DeepSpeed that referenced this pull request May 21, 2025
Resolves deepspeedai#6997

This PR conditionally quotes environment variable values—only wrapping
those containing special characters (like parentheses) that could
trigger bash errors. Safe values remain unquoted.

---------

Signed-off-by: Saurabh <saurabhkoshatwar1996@gmail.com>
Signed-off-by: Saurabh Koshatwar <saurabhkoshatwar1996@gmail.com>
Co-authored-by: Logan Adams <114770087+loadams@users.noreply.github.com>
Signed-off-by: yisheng <yi.sheng@intel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] mpi based training error

4 participants