Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to specify an alias for a parameter #54

Closed
jhzgjhzg opened this issue Jun 21, 2023 · 3 comments · Fixed by #83
Closed

How to specify an alias for a parameter #54

jhzgjhzg opened this issue Jun 21, 2023 · 3 comments · Fixed by #83

Comments

@jhzgjhzg
Copy link

jhzgjhzg commented Jun 21, 2023

If a parameter name is too complex and I want to specify its abbreviation, how should I write it.
Similar to this:
parser.add_argument("--target_img", "--ti", required=False, help="Path of reference image.")
--target_img and --ti

@brentyi
Copy link
Owner

brentyi commented Jun 29, 2023

Hi!

Unfortunately we haven't added alias support. If this is something important to you I could add it to my to-do list; I'd expect it to be straightforward.

In the meantime, it is possible to rename an argument:

import dataclasses
from pathlib import Path

import tyro
from typing_extensions import Annotated


@dataclasses.dataclass
class Args:
    target_image: Annotated[Path, tyro.conf.arg(name="ti")]


# Takes --ti as an argument.
tyro.cli(Args)

@vwxyzjn
Copy link
Contributor

vwxyzjn commented Oct 31, 2023

👀 hi running into the same issue. We have things like

    argparser.add_argument(
        "-t",
        "--temperature",
        help="Generation temperature",
        type=float,
        default=1.0
    )

    argparser.add_argument(
        "-toks",
        "--max-new-tokens",
        help="Max new tokens",
        type=int,
        default=1500
    )

@brentyi
Copy link
Owner

brentyi commented Oct 31, 2023

Ok, 0.5.12 should support aliases now. There's an example here: https://brentyi.github.io/tyro/examples/04_additional/11_aliases/

@jhzgjhzg for your example:

target_img: Annotated[Optional[Path], tyro.conf.arg(aliases=["--ti"])] = None

@vwxyzjn for yours:

temperature: Annotated[float, tyro.conf.arg(aliases=["-t])] = 1.0
max_new_tokens: Annotated[int, tyro.conf.arg(aliases=["-toks"]) = 1500

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 a pull request may close this issue.

3 participants