Skip to content
This repository has been archived by the owner on May 28, 2023. It is now read-only.

add typing in optuna_transformers #69

Closed
PhilipMay opened this issue Jul 9, 2021 · 6 comments
Closed

add typing in optuna_transformers #69

PhilipMay opened this issue Jul 9, 2021 · 6 comments

Comments

@PhilipMay
Copy link
Member

@twolffpiggott can you please tell me the type of this?

def setup(self, args: TrainingArguments, state: TrainerState, model):

@PhilipMay
Copy link
Member Author

@twolffpiggott what do you think? Can we remove this check since we use typing? Or change the check to check for Number?

if isinstance(v, (int, float)): # TODO: remove or change to Number?

@PhilipMay
Copy link
Member Author

@twolffpiggott I closed the merge request and opened the inline questions here again.

@twolffpiggott
Copy link
Collaborator

@twolffpiggott can you please tell me the type of this?

def setup(self, args: TrainingArguments, state: TrainerState, model):

Am I right to interpret your meaning as for the untyped model argument?

I left it untyped because I was not sure if there is a single Transformers base model type. Looking at this Transformers design document, it might be reasonable to put model: Union[transformers.PreTrainedModel, transformers.TFPreTrainedModel]

@twolffpiggott
Copy link
Collaborator

twolffpiggott commented Jul 9, 2021

@twolffpiggott what do you think? Can we remove this check since we use typing? Or change the check to check for Number?

if isinstance(v, (int, float)): # TODO: remove or change to Number?

The type hints aren't restrictive and will not prevent people from using the method incorrectly. We could use something like mypy though I'm not sure if this will cover all dynamic use cases.

Custom types like Numeric can be used for hints but not isinstance checks. Might be simplest to keep as is but here are some alternatives

@PhilipMay PhilipMay changed the title Typing in optuna_transformers add typing in optuna_transformers Jul 9, 2021
@PhilipMay
Copy link
Member Author

Am I right to interpret your meaning as for the untyped model argument?

Oops yes!

PhilipMay added a commit that referenced this issue Jul 9, 2021
@PhilipMay
Copy link
Member Author

done

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants