Simplified tyro version for dumb imperative CLI scripts
Hey there @brentyi ! Thank you for amazing library!
I've made a simple library called manuscript (which itself is based on tyro). It's inspired by Andrej Karpathy’s “poorman’s configuration system” that he used extensively in his projects like nanoGPT and a more recent nanochat.
It uses on-the-fly code patching/inline exec approach where it reads the with block and converts all variables defined there as configurable through CLI. Basically it intercepts the argparse and injects the values back. So like the following:
import manu
import manu.conf as conf
with manu.script as args:
exp_name: str = ... # required
out_dir: Path = ... # rich types supported
device = "cpu" # with default, type hint is optional
learning_rate = 6e-4 # inline comments become help text
beta = 0.9 #! comments with ! are ignored
max_iters = 6000000
"""this is a docstring for max_iters as well"""
do_something: conf.Fixed[bool] = True #! configure args via hints
# at this point `exp_name` is an actual runtime string
# so you can use it as usual
print("Using exp name:", exp_name)
# you can also do something with all the captured values
print("All CLI variables:")
print(args) # Mapping[str, Any]
# log final config to wandb, mlflow, etc.
# args is basically a mapping of all variables and their final values
wandb.config.update(manu.script.values) # same as args
I intend it to be a hustle free and pythonic configuration system for flat imperative style CLI scripts. I use it for my ML experiments for example. I've wanted to make something elegant and simple as well and I guess I kinda achieved that, or at least pretty close to something usable now.
So it’s not really an issue, just wanted to share it and give you a shoutout. Maybe someone reading this would find it useful! It’s currently in development and more like PoC stage so I would also much appreciate any feedback and maybe suggestions on design and potential improvements.
Hi @stllfe, this is super cool and clean, thanks for sharing! I just add a link from the README.
Especially if it's possible to implement this without pydantic, we could also exploring implementing an API like this directly in tyro.extras 👀
Hi @stllfe, this is super cool and clean, thanks for sharing! I just add a link from the README.
Especially if it's possible to implement this without pydantic, we could also exploring implementing an API like this directly in
tyro.extras👀
Yay! Thank you for reply! It inspires me to put some proper effort into tests and polish the UX further. As for the pydantic, I'll definitely look into making it an optional dependency. Is it possible then to borrow some type/schema validation functionality right from the tyro itself?
Is it possible then to borrow some type/schema validation functionality right from the tyro itself?
This seems possible, but actually I don't have a good sense of what needs to be validated here! Do you have concrete things in mind?