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

HfArgumentParser should parse hyphens in long-option parameters #33933

Open
djmarti opened this issue Oct 3, 2024 · 1 comment
Open

HfArgumentParser should parse hyphens in long-option parameters #33933

djmarti opened this issue Oct 3, 2024 · 1 comment
Labels
Feature request Request for a new feature

Comments

@djmarti
Copy link

djmarti commented Oct 3, 2024

Feature request

Given a dataclass

from dataclasses import dataclass

@dataclass
class Config:
    item_type: str
    item_length: int

I would expect HfArgumentParser.parse_args_into_dataclasses to correctly parse parameters like --item-type or --item-length (with a hyphen instead of an underscore). Unfortunately, it doesn't:

from transformers import HfArgumentParser
parser = HfArgumentParser([Config])
parser.parse_args_into_dataclasses(args=["--item-type", "my_type", "--item-length", "23"])

throws an error because it is expecting --item_type and --item_length.

Motivation

  1. Consistency with argparse. argparse converts hyphens into underscores before assignment:

    If no long option strings were supplied, dest will be derived from the first short option string by stripping the initial - character. Any internal - characters will be converted to _ characters to make sure the string is a valid attribute name.

  2. It is standard convention to use hyphens in long-option parameters (e.g., --file-type, not --file_type).

Your contribution

If there is no reason preventing this feature request to be accepted, yes, I could contribute to a PR.
I just want to know if there is a fundamental reason why this is not implemented yet.

@djmarti djmarti added the Feature request Request for a new feature label Oct 3, 2024
@ArthurZucker
Copy link
Collaborator

yeah feel free to open a PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature request Request for a new feature
Projects
None yet
Development

No branches or pull requests

2 participants