如何让wandb按位置传递参数?
我正在尝试探索 python 脚本“train.py”上不同参数设置的结果。为此,我使用了 wandb 扫描。每个 wandb 代理都会执行文件“train.py”并向其传递一些参数。根据 wandb 文档 (https://docs.wandb.ai/guides/sweeps/配置#command),例如两个参数“param1”和“param2”的情况下,每个代理使用命令启动文件。
/usr/bin/env python train.py --param1=value1 --param2=value2
但是,“train.py”期望
/usr/bin/env python train.py value1 value2
并按位置解析参数值。我没有编写 train.py,并且希望尽可能不更改它。如何让 wandb 传递前面没有“--param1=”的值?
I am trying to explore the results of different parameter settings on my python script "train.py". For that, I use a wandb sweep. Each wandb agent executes the file "train.py" and passes some parameters to it. As per the wandb documentation (https://docs.wandb.ai/guides/sweeps/configuration#command), in case of e.g. two parameters "param1" and "param2" each agents starts the file with the command
/usr/bin/env python train.py --param1=value1 --param2=value2
However, "train.py" expects
/usr/bin/env python train.py value1 value2
and parses the parameter values by position. I did not write train.py and would like to not change it if possible. How can I get wandb to pass the values without "--param1=" in front?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要认为您可以从 W&B Sweeps 中获得位置参数。不过,您可以尝试一些不需要接触
train.py
文件的解决方法。您可以创建一个调用程序文件,我们将其命名为
invoke.py
。现在,您可以使用它删除关键字参数名称。像这样的东西可能会起作用:这允许您调用
train.py
文件,如下所示:现在要执行 W&B 扫描,您可以创建一个
command:
部分 (参考)在您的sweeps.yaml
文件中扫描参数param0
和param1
。例如:Don't think you can get positional arguments from W&B Sweeps. However, there's a little work around you can try that won't require you touching the
train.py
file.You can create an invoker file, let's call it
invoke.py
. Now, you can use it get rid of the keyword argument names. Something like this might work:This allows you to invoke your
train.py
file as follows:Now to perform W&B sweeps you can create a
command:
section (reference) in yoursweeps.yaml
file while sweeping over the parametersparam0
andparam1
. For example: