marimo-batch
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePydantic is a great way to declare a source of truth for a batch job, especially for ML. You can declare something like:
python
from pydantic import BaseModel, Field
class ModelParams(BaseModel):
sample_size: int = Field(
default=1024 * 4, description="Number of training samples per epoch."
)
learning_rate: float = Field(default=0.01, description="Learning rate for the optimizer.")You can fill these model params with two methods too, you can imagine a form in the UI.
python
el = mo.md("""
{sample_size}
{learning_rate}
""").batch(
sample_size=mo.ui.slider(1024, 1024 * 10, value=1024 * 4, step=1024, label="Sample size"),
learning_rate=mo.ui.slider(0.001, 0.1, value=0.01, step=0.001, label="Learning rate"),
).form()
elBut you can also use the CLI from marimo.
python
if mo.app_meta().mode == "script":
model_params = ModelParams(
**{k.replace("-", "_"): v for k, v in mo.cli_args().items()
})
else:
model_params = ModelParams(**el.value)The user can now run this from the command line via:
bash
uv run notebook.py --sample-size 4096 --learning-rate 0.005This is the best of both worlds, you can use the UI to test and iterate, and then use the CLI to run the batch job.
The user wants to be able to run a notebook using this pattern, so make sure you ask the user which parameters they want to make configurable via the CLI and the proceed to make the changes to the notebook. Make sure you verify the changes with the user before making them.
Pydantic是为批处理任务(尤其是机器学习(ML)任务)定义可信数据源的绝佳方式。你可以这样定义:
python
from pydantic import BaseModel, Field
class ModelParams(BaseModel):
sample_size: int = Field(
default=1024 * 4, description="Number of training samples per epoch."
)
learning_rate: float = Field(default=0.01, description="Learning rate for the optimizer.")你也可以通过两种方式填充这些模型参数,比如在UI中使用表单:
python
el = mo.md("""
{sample_size}
{learning_rate}
""").batch(
sample_size=mo.ui.slider(1024, 1024 * 10, value=1024 * 4, step=1024, label="Sample size"),
learning_rate=mo.ui.slider(0.001, 0.1, value=0.01, step=0.001, label="Learning rate"),
).form()
el不过你也可以使用marimo的CLI:
python
if mo.app_meta().mode == "script":
model_params = ModelParams(
**{k.replace("-", "_"): v for k, v in mo.cli_args().items()
})
else:
model_params = ModelParams(**el.value)用户现在可以通过命令行运行此脚本:
bash
uv run notebook.py --sample-size 4096 --learning-rate 0.005这是两全其美的方案:你可以使用UI进行测试和迭代,然后通过CLI运行批处理任务。
用户希望能够按照此模式运行notebook,因此请务必询问用户希望通过CLI配置哪些参数,然后再对notebook进行修改。修改前请务必与用户确认变更内容。
Weights and Biases
Weights and Biases
It is possible that the user is interested in adding support for weights and biases. If that is the case, make sure these ModelParams are logged.
用户可能有兴趣添加Weights and Biases的支持。如果是这种情况,请确保将这些ModelParams记录到Weights and Biases中。