brentyi / tyro

CLI interfaces & config objects, from types
https://brentyi.github.io/tyro
MIT License
467 stars 23 forks source link

tyro.cli error when unpacking command line arguments in AzureML environment #138

Closed Yuxin-99 closed 4 months ago

Yuxin-99 commented 4 months ago

Hi!

I am encountering an error when using tyro.cli to parse command line arguments in an AzureML environment. The script works perfectly locally, but fails when executed on AzureML with a ValueError related to unpacking values. Switching to argparse resolves the issue on Azure, suggesting that the problem may be specific to tyro.

Environment

Python Version: 3.11
Tyro Version: 0.7.3
Operating System: AzureML environment (ubuntu22.04 image)

The error message:

Traceback (most recent call last):
  File "train.py", line 75, in main
    params = tyro.cli(InputParameters)
  File "tyro/_cli.py", line 443, in _cli_impl
    namespace = parser.parse_args(args=args)
  File "tyro/_argparse_formatter.py", line 495, in _parse_known_args
    start_index = consume_optional(start_index)
  File "tyro/_argparse_formatter.py", line 362, in consume_optional
    action, option_string, explicit_arg = option_tuple
ValueError: too many values to unpack (expected 3)

Here is a simplified snippet of the code (train.py):

from dataclasses import dataclass
import tyro

@dataclass
class InputParameters:
    data_path: str | None = None
    max_epoch_number: int = 1

def main():
    params = tyro.cli(InputParameters)  # This line causes the error on AzureML
    assert params.data_path is not None

if __name__ == "__main__":
    main()

And the relevant part of launching the job to run the script (train.py) for AzureML:

job_inputs = dict(
    input_data=Input(
        type=AssetTypes.URI_FOLDER,  # type: ignore
        path=input_dataset.path,
    ),
    max_epoch_number=5,
)

job = command(
    inputs=job_inputs,
    command=(
        "python3.11 scripts/train.py "
        "--data_path ${{inputs.input_data}} "
        "--max_epoch_number ${{inputs.max_epoch_number}}"
    ),
    # additional job config
)

Expected behavior The script should parse the command line arguments without errors like how it behaves on my local machine.

Actual behavior The script fails with the ValueError: too many values to unpack. But when I use argparse to parse the arguments, it doesn't fail.

Thank you in advance!

brentyi commented 4 months ago

Hello! Can you confirm that you're on the latest version of tyro? Python 3.11.9 broke some things, but they should be fixed in tyro==0.8.3.

Yuxin-99 commented 4 months ago

Hi! Thanks a lot for your answer! I didn't notice there is a newer version of Tyro for python3.11. Now the issue is solved. Thank you!