Allow argument dependencies
See original GitHub issueIs your feature request related to a problem? Please describe.
I am wondering if its possible to tie some argument values together. For example, when I train an Encoder-Decoder architecture, the encoder.output_dim should be the same like decoder.input_dim.
Describe the solution you’d like
I would like to specify only one of them in the CLI and have the other be set automatically. And if I accidentally specify both, I would like to be yelled at for doing something wrong.
How it could work:
dim: int = TiedParam(default=25)
@dataclass
class Encoder:
output_dim: int = dim
@dataclass
class Decoder:
input_dim: int = dim
Let me know what you think (or forgive my ignorance if its already possible!! 😃) Thanks!
Issue Analytics
- State:
- Created a year ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
8. Dependencies with Arguments - FastapiTutorial
Pass arguments to a class based dependency in FastAPI. ... We want to allow our website users to search for jobs by providing...
Read more >Declaring gradle dependencies with arguments - Stack Overflow
I would like for a module to be able to accept an argument from a module that specifies it as a dependency. Can...
Read more >Adding dependencies to pattern parameters - IBM
Pattern parameter dependencies are created between only two parameters. The Pattern Authoring view allows the entry of multiple supplier or client ...
Read more >Dependency injection is passing an argument - ploeh blog
This is the application of a design pattern called constructor injection. It captures the dependencies in class fields, making them available ...
Read more >8 Avoid dependencies between arguments
Avoid creating dependencies between details arguments so that only certain combinations are permitted. Dependencies between arguments makes functions harder ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@janvainer what you propose already exists in jsonargparse, see argument-linking. You might want to try that out.
Hey there @janvainer, thanks for posting this!
Hmm that’s interesting. From what is currently implemented, you have two options to take a look at, none of which do exactly what you want… 😞
This isn’t directly related to simple-parsing, it’s just a little feature for dataclasses that I’ve made into a shareable code snippet using GitHub Gist. Here’s the idea:
The problem with this though is that I don’t think it works if the fields are on different dataclasses… You might be able to tweak the
conditional_field
function to achieve it though. If you do, please do let me know!dest
to thefield
function:This doesn’t really do what you want, and doesn’t really work as intended, in its current state. (I wrote this waaaaay back, and haven’t used it or tested it since…)
Hope this is somewhat helpful. I’d be really curious to hear some more ideas on how we could design this! The
TiedField
idea seems interesting. Perhaps we could also make use of type annotations for this somehow?Let me know what you think! 😃