question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't cast Trainer automatically generated args to their required types

See original GitHub issue

❓ Questions and Help

What is your question?

I’m not sure, that this is a bug, so I put it like a question. The problem is: if I want to add the Trainer arguments to my custom ArgumentParser object, I call the add_argparse_args Trainer classmethod. But this method doesn’t cast the Trainer arguments to their required types. It forces me to cast the arguments by myself. Like so:

trainer_args.update(
        {
            'accumulate_grad_batches': int(trainer_args['accumulate_grad_batches']),
            'train_percent_check': float(trainer_args['train_percent_check']),
            'val_percent_check': float(trainer_args['val_percent_check']),
            'val_check_interval': int(trainer_args['val_check_interval']),
            'track_grad_norm': int(trainer_args['track_grad_norm']),
            'max_epochs': int(trainer_args['max_epochs']),
            'precision': int(trainer_args['precision']),
            'gradient_clip_val': float(trainer_args['gradient_clip_val']),
        }
)

And after that, I can pass updated arguments to the Trainer:

trainer = pytorch_lightning.Trainer(
        **trainer_args
)

And I can’t find a central place, where the Trainer handles an automatically generated arguments (their types).

What have you tried?

I’ve tried to pass arguments to the trainer without handling their types. For instance, if i’ll not cast accumulate_grad_batches to the integer type, the exception will be raised:

TypeError: Gradient accumulation supports only int and dict types

What’s your environment?

  • OS: [Linux]
  • Packaging [pip]
  • Version [0.7.1]

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
alexeykarnachevcommented, Mar 17, 2020

@williamFalcon this issue is about assigning types for the automatically added arguments. By default argparser assumes that they are strings. And these string typed args will be passed to the trainer constructor, and will break it. So, this issue is about types casting, but not about any new functionality

Read more comments on GitHub >

github_iconTop Results From Across the Web

Trainer - Hugging Face
The Trainer class provides an API for feature-complete training in PyTorch for most standard use cases. It's used in most of the example...
Read more >
Casting and type conversions - C# Programming Guide
Learn about casting and type conversions, such as implicit, explicit (casts), and user-defined conversions.
Read more >
Training Pipelines & Models · spaCy Usage Documentation
This is an auto-generated partial config. To use it with 'spacy train' # you can run spacy init fill-config to auto-fill all default...
Read more >
Create Parameters - Tableau Help
A parameter is a workbook variable such as a number, date, or string that can replace a constant value in a calculation, filter,...
Read more >
Image Classification — TAO Toolkit 3.22.05 documentation
This parameter is overriden by the learning rate scheduler and hence not useful. float. 0.01. Training the model¶. Use the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found