marimo-batch by marimo-team/skills
npx skills add https://github.com/marimo-team/skills --skill marimo-batchPydantic 是声明批处理任务(尤其是机器学习任务)数据源的绝佳方式。你可以像这样声明:
from pydantic import BaseModel, Field
class ModelParams(BaseModel):
sample_size: int = Field(
default=1024 * 4, description="每个训练周期的样本数量。"
)
learning_rate: float = Field(default=0.01, description="优化器的学习率。")
你也可以通过两种方式填充这些模型参数,可以想象在用户界面中有一个表单。
el = mo.md("""
{sample_size}
{learning_rate}
""").batch(
sample_size=mo.ui.slider(1024, 1024 * 10, value=1024 * 4, step=1024, label="样本大小"),
learning_rate=mo.ui.slider(0.001, 0.1, value=0.01, step=0.001, label="学习率"),
).form()
el
但你也可以使用 marimo 的命令行界面。
if mo.app_meta().mode == "script":
if "help" in mo.cli_args() or len(cli_args) == 0:
print("用法: uv run git_archaeology.py --repo <url> [--samples <n>]")
print()
for name, field in ModelParams.model_fields.items():
default = f" (默认值: {field.default})" if field.default is not None else " (必需)"
print(f" --{name:12s} {field.description}{default}")
exit()
model_params = ModelParams(
**{k.replace("-", "_"): v for k, v in mo.cli_args().items()
})
else:
model_params = ModelParams(**el.value)
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
用户现在可以通过命令行运行此程序:
uv run notebook.py --sample-size 4096 --learning-rate 0.005
这结合了两者的优点,你可以使用用户界面进行测试和迭代,然后使用命令行界面运行批处理任务。另一个好处是,你可以使用设置运行笔记本,使其快速运行以查看笔记本中是否存在任何错误。
用户希望能够使用这种模式运行笔记本,因此请确保询问用户他们希望通过命令行界面配置哪些参数,然后继续对笔记本进行更改。在进行更改之前,请务必与用户核实这些更改。
用户可能对添加 Weights and Biases 支持感兴趣。请务必确认是/否。如果是这种情况,请确保记录这些 ModelParams。如果用户希望采用此路径,你还需要确保 wandb_project 和 wandb_run_name 是 ModelParams 的一部分。
如果用户热衷于启动机器学习训练任务,请务必使用此起点。请确保在此笔记本中保持列结构完整!
你可能需要为任务读取环境变量。如果存在 .env 文件,请使用 python-dotenv 读取它,但也要添加一个 EnvConfig,以便用户可以在用户界面中手动添加密钥。
from wigglystuff import EnvConfig
# 使用验证器
config = EnvConfig({
"OPENAI_API_KEY": lambda k: openai.Client(api_key=k).models.list(),
"WANDB_API_KEY": lambda k: wandb.login(key=k, verify=True)
})
# 阻塞直到有效,在需要密钥的单元格中很有用
config.require_valid()
# 访问值
config["OPENAI_API_KEY"]
config.get("OPENAI_API_KEY", "some default")
请务必将此 EnvConfig 添加到笔记本的顶部。
对于较大的 marimo 笔记本,使用列功能来简化导航是很常见的。如果是这种情况,你必须保持这些列结构完整!
@app.cell(column=0, hide_code=True)
def _(mo):
mo.md(r"""demo""")
每周安装次数
603
代码仓库
GitHub 星标数
77
首次出现
2026年2月10日
安全审计
安装于
claude-code472
codex407
opencode348
github-copilot324
gemini-cli323
kimi-cli319
Pydantic is a great way to declare a source of truth for a batch job, especially for ML. You can declare something like:
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.
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
But you can also use the CLI from marimo.
if mo.app_meta().mode == "script":
if "help" in mo.cli_args() or len(cli_args) == 0:
print("Usage: uv run git_archaeology.py --repo <url> [--samples <n>]")
print()
for name, field in ModelParams.model_fields.items():
default = f" (default: {field.default})" if field.default is not None else " (required)"
print(f" --{name:12s} {field.description}{default}")
exit()
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:
uv run notebook.py --sample-size 4096 --learning-rate 0.005
This 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. Another benefit is that you can run the notebook with settings to make it run quickly to see if there are any bugs in the notebook.
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.
It is possible that the user is interested in adding support for weights and biases. Make sure you confirm if this is the case yes/no. If that is the case, make sure these ModelParams are logged. You also want to make sure that the wandb_project and wandb_run_name are part of the ModelParams is the user wants to go down this route.
If the user is keen to start a training job for ML, make sure you use this starting point. Make sure you keep the columns intact in this notebook!
You may need to read environment variables for the job. Use python-dotenv to read a .env file if it exists, but also add an EnvConfig so users may add keys manually in a ui.
from wigglystuff import EnvConfig
# With validators
config = EnvConfig({
"OPENAI_API_KEY": lambda k: openai.Client(api_key=k).models.list(),
"WANDB_API_KEY": lambda k: wandb.login(key=k, verify=True)
})
# Block until valid, useful in cell that needs the key
config.require_valid()
# Access values
config["OPENAI_API_KEY"]
config.get("OPENAI_API_KEY", "some default")
Make sure you add this EnvConfig at the top of the notebook.
It can be common for larger marimo notebooks to use the columns feature to make it easy to navigate. If that is the case, you must keep these columns intact!
@app.cell(column=0, hide_code=True)
def _(mo):
mo.md(r"""demo""")
Weekly Installs
603
Repository
GitHub Stars
77
First Seen
Feb 10, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
claude-code472
codex407
opencode348
github-copilot324
gemini-cli323
kimi-cli319
AI 代码实施计划编写技能 | 自动化开发任务分解与 TDD 流程规划工具
41,400 周安装