Bailian RL Deploy
Train and deploy reinforcement learning models on Alibaba Cloud Bailian.
Installation
- Make sure Claude is on your device and in your terminal.
Skills load from
~/.claude/skills/when Claude Code starts up β so you need it on your machine first. If you don't have it yet, install it once with the command below, then runclaudein any terminal to verify.One-time setupnpm i -g @anthropic-ai/claude-codeAlready have it? Skip ahead.
- Paste into Claude Code or into your terminal.
This copies the whole skill folder into
~/.claude/skills/bailian-rl-deploy-modelstudioai/β the SKILL.md plus any scripts, reference docs, or templates the skill ships with. Works for every skill.What this command does
- Makes a new, empty temporary folder.
- Downloads the skill's folder,
skills/bailian-rl-deploy, fromgithub.com/modelstudioai/skills(branchmain), the GitHub repository it's listed from. You get the version that is there now, not a copy we keep. - Copies that folder to
~/.claude/skills/bailian-rl-deploy-modelstudioai/. - Deletes the temporary folder.
Installing runs none of the skill's files; it only downloads and copies them. When you later use the skill, Claude follows its SKILL.md and may run scripts that come with it. Read them first.
Faster alternative (instruction-only skills)
Skips the clone and grabs only the SKILL.md file. Don't use this if the skill ships Python scripts, reference markdowns, or asset templates β they won't be downloaded and the skill will fail when it tries to load them.
Quick install (SKILL.md only)Sign up to copy - Restart Claude Code.
Quit and reopen Claude Code (or any other agent that loads from
~/.claude/skills/). New skills are picked up on startup. - Just ask Claude.
Skills auto-activate when your request matches the skill's description β no slash command needed. Trigger phrases live in the skill's own frontmatter; you can read them in the βWhat this skill doesβ section above.
Prefer to read the source first? Open on GitHub.
When Claude uses it
End-to-end reinforcement-learning training and deployment on Alibaba Cloud Bailian / DashScope with the `bl` CLI β authorize β sandbox runtime β data & Rollout/Reward code β submit RL job β monitor β publish checkpoint β deploy & invoke. Covers bl finetune rl authorize / run / watch / logs / get / list / cancel / delete, bl finetune runtime prepare / doctor / clean, and post-training checkpoints / export / deploy. Activate whenever the user wants "reinforcement learning", "RL training", "GRPO/GSPO", "AgenticRL", "reward function", "rollout function", "math-reasoning training", "agent tool-calling training", "MTU training units", "rl run", or "submit an RL job" on Bailian / DashScope β even without saying "use bl"; do not hand-assemble commands or make the user write submit_job.py. Underspecified requests must go through the Step 0 intake (ask the user for model / data / Rollout-Reward code / billing / deploy intent) before any action β never answer a training request with doc summaries or code samples. Not for SFT / DPO / CPT / LoRA supervised fine-tuning or OPD distillation (pg_opd / teacher_model) β those go to bailian-finetune; training on other platforms, plain Q&A / coding / model selection do not trigger this skill.
What this skill does
Bailian RL training β deployment loop (bl finetune rl)
Submit, monitor, and deploy your first RL training job with the Bailian CLI bl. RL drives the model to explore optimal policies through a generate (Rollout) β score (Reward) β optimize loop β no ground-truth labels required. Well suited to math reasoning, agent tool calling, and code generation.
0. Intake (mandatory) inputs missing? ask the user first β model / data / functions / billing / deploy
1. Auth & environment bl auth status β bl finetune rl authorize β runtime prepare β runtime doctor
2. Data & code JSONL (messages + rollout_extra) + Rollout/Reward function package (official demo available)
3. Submit bl finetune rl run --dry-run preview β user confirms β --yes submit (optionally --watch)
4. Monitor bl finetune rl watch / logs / get + console Metrics tab (critic/rewards/mean)
5. Publish & deploy last checkpoint auto-published β bl deploy text create β invoke via bl text chat
Read the shared protocol before executing
../bailian-protocol/SKILL.md: version pre-flight, call attribution, auth, error reporting. If the protocol file is missing, stop runningbland promptbl skill init. Command details are authoritative inbl <command> --helpand skillbailian-finetune'sreference/finetune.mdβ do not guess flags.
Call attribution (wrap every agent-initiated bl command; inline samples below are for one-off runs β when copying into reusable scripts, use the protocol's script template):
BAILIAN_CALLER_TYPE=agent BAILIAN_CALLER_NAME=qoder BAILIAN_SKILL_NAME=bailian-rl-deploy BAILIAN_SKILL_VERSION=1.0.0 bl finetune rl authorize
Step 0: Intake β clarify missing inputs before acting (mandatory)
A submission needs five decisions. When the trigger message does not supply them, stop and ask the user β one compact round of questions with recommended defaults. Do not read official docs, do not generate code samples, and do not run any bl write command before the intake is settled:
| # | Input | Ask | Default to offer |
|---|---|---|---|
| 1 | Base model | Which model to train? | qwen3.5-9b (field-verified) |
| 2 | Training data | Own JSONL path(s), or the official demo data? | demo calc_train_min.jsonl + calc_validation_min.jsonl |
| 3 | Rollout/Reward code | Own function package path, or the official demo? | demo agentic-rl-example (math-calculation agent) |
| 4 | Billing | MTU spec Γ count; postpaid or prepaid? | MTU4 Γ 24, mtu_postpaid β CNY 984/hour β disclose the cost |
| 5 | After training | Deploy automatically and hand off a call example? | yes |
- One-shot escape hatch: offer "use the official demo with the verified defaults" β accepting it settles all five inputs at once; the user then only confirms the disclosed cost at the Step 3 gate.
- Only after all five are settled (answered or explicitly defaulted) proceed to the version/platform gates and Step 1. The Step 3 dry-run β confirm β
--yesbilling gate still applies on top β intake does not replace it. - The deliverable is a submitted
bljob, not documentation or code. Never respond to a training request with a hand-written SDK script (submit_job.pyetc.), a doc summary, or generic code examples. If the user explicitly wants learning material / SDK sample code instead of running a job, that is out of scope β point to the official docs and stop. - Inputs already given in the trigger message are not re-asked; only the missing ones are.
Version & platform gates (start of the action flow)
- CLI version: proceed only if
bl finetune rl run --helpprints normally. The RL command group is recent β older CLIs lack it; upgrade withbl updatefirst. During development you can use the repo entrypnpm -s bl(note its cwd is pinned topackages/cli; see the path rules below). - Platform: the RL sandbox supports macOS / Linux only; Windows fails closed with "Not supported on Windows yet." β do not try to bypass it. OPD has no such restriction (but OPD is out of scope for this skill).
- Auth:
bl auth status; if unauthenticated,bl auth login --api-key sk-...first. Theblpath does not require a local Python / dashscope SDK install β the CLI ships a reviewed managed runtime (pinned CPython + dashscope baseline) that is downloaded, verified, and cached automatically. Thepip install dashscopeinstructions in official docs apply only to the hand-written SDK-script path. - Access whitelist: RL training must be enabled by your account manager. If the authorize probe reports
REQUIRES_USER_ACTION/ missing whitelist, hand the enablement guidance back to the user; do not retry in a loop.
Write-operation guardrails (read before submitting)
-
RL supports MTU (Model Training Unit) billing only β no per-token billing. These are dedicated training resources; billing starts at creation:
Billing --charge-typeUnit price (type-IV MTU4) Notes Postpaid mtu_postpaidCNY 41.00/hour/instance (1-minute granularity) Provisioned directly at job creation; no pre-purchase Prepaid mtu_prepaidCNY 19,914.00/month/instance Requires --instance-id(get it from your account manager); early unsubscribe billed at 1.2Γ the hourly rateThe official demo (qwen3.5-9b) needs at least 24 Γ MTU4 β CNY 984/hour (postpaid). Before submitting you must explicitly state spec Γ count Γ estimated duration and the cost magnitude to the user, and get confirmation.
-
mtu_capacityhard formula:--mtu-countmust strictly equalnnodes_rollout Γ n_gpus_rollout + nnodes_training Γ n_gpus_training(all four live inhyper_parameters; defaults differ per model). When tuning parallelism hyperparameters, update--mtu-countin lockstep. Recommended starting points: qwen3.5-9b β 24; qwen3.6-flash-2026-04-16 / qwen3.5-flash-2026-02-23 / qwen3.6-35b-a3b (MoE) β 40. -
dry-run β user confirmation β
--yes:rl run/rl cancel/rl delete/rl authorize --authorize/runtime cleanare allrisk: high. Preview with--dry-runfirst (rl run's dry-run is zero-network, zero-billing), then hand the preview and cost back to the user; never add--yesautomatically. On exit code 7 /requires_confirmation, stop and ask for confirmation β that is normal control flow, not a bug; re-confirm whenever the target or scope changes. -
A
--watchtimeout only stops waiting β it never cancels the cloud job (same for--wait-timeout/--poll-timeout). The job keeps billing; only an explicitrl cancelstops it.
Step 1: Authorization & sandbox runtime
bl finetune rl authorize # read-only probe (Console auth); per-item READY/MISSING/UNKNOWN/REQUIRES_USER_ACTION
bl finetune rl authorize --authorize --yes # enable RL business mode only after user confirmation AND prerequisites READY (never creates roles, never enables OPD)
bl finetune runtime prepare # first-time download & verification of the managed runtime (local only, no cloud resources)
bl finetune runtime doctor # read-only health check: credential deny-read / home redirect / SDK import / host network reachability (advisory) etc.; non-zero exit on failure
The CLI never creates service-linked roles (SLR). Role authorization is an account-level grant that only the user can perform in the console. The probe reports six checks:
| Check | Required? | Not READY means | Agent action |
|---|---|---|---|
whitelist | yes | RL admission not granted (REQUIRES_USER_ACTION) | Hand back to user: enablement via account manager; do not retry in a loop |
finetune-slr | yes | Fine-tuning SLR missing (covers FC and SLS roles) β REQUIRES_USER_ACTION, blocks enablement | Stop; guide the user to console one-click authorization per the doc below; re-run the probe after the user confirms completion |
telemetry-slr | no (advisory) | Xtrace telemetry SLR missing β REQUIRES_USER_ACTION | Same console guidance; does not block ok or submission |
apptrace-service | no (advisory) | AppTrace not activated (console purchase page) | Manual console step; advisory only |
sls-service | no (advisory) | Static manual reminder, always REQUIRES_USER_ACTION β the CLI never probes or opens SLS | Tell the user SLS activation is a separate manual console step; its SLR is already covered by finetune-slr. Not an error β do not try to clear it via CLI |
business-enabled | yes | RL training mode not enabled | --authorize --yes enables it only when whitelist + finetune-slr are already READY |
- Stop-and-guide rule: any required
REQUIRES_USER_ACTIONβ stop the flow, give the user the console authorization guidance (model-tuning page one-click authorization; doc: https://docs.bailian.console.aliyun.com/zh/model-studio/rl-training-overview#%E7%8E%AF%E5%A2%83%E5%87%86%E5%A4%87 ), wait for the user to complete it, then re-runbl finetune rl authorizeto verify. Never attempt role creation through any CLI/API path, and never treat advisory items as blockers. --authorizeonly flips business enablement; with missing prerequisites it does nothing β roles must be authorized manually first.ok: truerequires every required check READY; advisory degradation does not fail the report.- Query failures are always
UNKNOWNβ never assume enabled. - Mirror switches for stuck downloads (integrity verification is never skipped):
BAILIAN_RL_PYTHON_MIRROR(custom CPython mirror prefix; built-in npmmirror fallback);BAILIAN_RL_PIP_INDEX_URL(PyPI mirror, e.g.https://pypi.tuna.tsinghua.edu.cn/simple/). If a mirror lags behind PyPI, pip fails closed withNo matching distribution found for X==verβ switch to a fresher mirror or back to default PyPI. - For development,
BAILIAN_RL_RUNTIMEcan point at a local dashscope Python directory to skip release verification (integration debugging only). - Agent host sandboxes may block outbound network (e.g. Codex's default
workspace-writedisables network and restricts writes to the workspace):runtime preparedownloads andrl runsubmission then fail with connect-levelEPERM/EACCES/ENETUNREACHβ switching mirrors does not help.runtime doctorprobes host reachability (API / CPython download / PyPI) as the advisoryhost-network-reachabilitycheck: ondegraded, stop and either (a) enable network access for the agent (Codex:sandbox_workspace_write.network_access = true), or (b) runruntime prepareand the submission in a regular terminal. The CLI honorsHTTPS_PROXY/HTTP_PROXY(upper- or lowercase) when an egress proxy is available. Provisioning is one-time β a READY runtime is reused across runs, so preparing once in a regular terminal unblocks later agent runs; submission itself always needs network.
Step 2: Prepare data & code
Fastest path β the official demo (math-calculation agent, minimum 24 Γ MTU4): download agentic-rl-example.zip; key structure after extraction:
agentic-rl-example/
βββ job.yaml β YAML submission config (feed directly to bl finetune rl run --config-file)
βββ data/calc_train_min.jsonl / calc_validation_min.jsonl β minimal data (recommended for the first run)
βββ functions/rollout/rollout.py β Rollout: LangGraph + MCP calculator tool
βββ functions/reward/reward.py β Reward: scores against the reference answer
βββ requirements.txt β function business dependencies (only packaged & uploaded to FC; never installed into the local sandbox)
Data format (JSONL, one object per line):
{"messages": [{"content": "Output the answer when you are ready. The answer should be surrounded by three sharps (`###`), in the form of ### ANSWER: <answer> ###. 6.6 minus x (3/2) times equals 5.6.", "role": "user"}], "rollout_extra": {"solution": "2/3"}}
messages: the user question in ChatML format;rollout_extra: reference answer / business data, passed through to Rollout'sRolloutInput.rollout_extraand Reward'sRewardInput.agent_output.rollout_extra. Keys are user-defined (not limited tosolution).- Volume: tens to hundreds of rows suffice to validate the pipeline, but the count must exceed batch_size; larger is steadier for real training.
- Upload package limit 200 MB; use
--exclude <glob>(repeatable) to strip.git/data/__pycache__etc. (maps to the SDK'sFC_ZIP_EXCLUDE_PATTERNS);--include <glob>for the inverse selection. - Custom Rollout / Reward development β official guide https://docs.bailian.console.aliyun.com/zh/model-studio/rl-function-development-guide . Metric names returned by the Reward function must match the
--reward-metrickeys verbatim (e.g. a function returning{"accuracy":β¦, "format":β¦}pairs with--reward-metric reward-1.accuracy=0.7); mismatches silently drop weights.
Step 3: Submit the training job
Preview the spec with dry-run first (zero network, zero billing); the user adds --yes after confirming:
bl finetune rl run \
--model qwen3.5-9b \
--train-file /abs/path/data/calc_train_min.jsonl \
--validation-file /abs/path/data/calc_validation_min.jsonl \
--code-dir /abs/path/agentic-rl-example \
--requirements requirements.txt \
--rollout functions.rollout.rollout.CalcXRolloutProcessor \
--reward reward-1=functions.reward.reward.DemoRewardProcessor \
--reward-metric reward-1.accuracy=0.7 --reward-metric reward-1.format=0.3 \
--hp algorithm=gspo --hp batch_size=64 --hp eval_steps=1 --hp kl_loss_coef=0.002 \
--hp learning_rate=2e-6 --hp lr_scheduler_type=linear --hp max_length=8192 \
--hp n_epochs=1 --hp n_rollouts=8 --hp ppo_mini_batch_size=8 --hp save_strategy=epoch \
--charge-type mtu_postpaid --mtu-spec MTU4 --mtu-count 24 \
--dry-run
- The 11
--hpentries above are the field-verified required starting set for qwen3.5-9b (non-MoE) GSPO β the server enforces required hyperparameters (an emptyhyper_parametersis rejected with 400, e.g.n_epochs is required.). Do not assume the platform fills defaults and omit the whole set. MoE models (qwen3.6-35b-a3b etc.) have different required sets and defaults β check https://docs.bailian.console.aliyun.com/zh/model-studio/rl-training-config-monitoring ; do not copy blindly. - Path rules:
--code-dir/--train-file/--validation-fileresolve against the CLI process cwd β when running across directories (especiallypnpm -s bl, whose cwd is pinned topackages/cli), always use absolute paths. The single exception:--requirementsmust stay relative to code-dir (the SDK doesjoin(zipdir, requirements_path)internally). --rollout <classpath>with a bare classpath defaults the function name torollout-1;--rewardrequires explicitname=classpath. Optional function tuning:--function-timeout name=seconds,--function-runtime name.field=value(cpu/memory_size/concurrency etc.),--reward-weight name=value,--function-env name.KEY=value; all can be omitted on the first run.- YAML-equivalent path: if the demo ships
job.yaml, runbl finetune rl run --config-file /abs/path/job.yaml --dry-rundirectly; explicit flags override same-named YAML fields, and--clear-functionsempties the YAML functions section. Both submission styles produce an equivalent spec β pick one. - Reuse uploaded data:
--train-file-id <id>/--validation-file-id <id>(obtained viabl dataset upload). - If the runtime has never been prepared, add
--install-runtimeto allow in-place installation; otherwise run Step 1'sruntime preparefirst. - On successful submission, record the
job_id(formft-xxx). Add--watchto block-poll until a terminal state (--wait-timeout <seconds>only stops waiting, never cancels the job).
Step 4: Monitor training
bl finetune rl watch --job-id ft-xxx # single non-blocking probe
bl finetune rl watch --job-id ft-xxx --follow --interval 10 # poll to terminal state (non-zero exit on FAILED/CANCELED)
bl finetune rl logs --job-id ft-xxx --offset 0 --lines 100 # training logs
bl finetune rl get --job-id ft-xxx # job details
bl finetune rl list --page 1 --size 20 # job history
- Training typically takes tens of minutes to hours. Watch
critic/rewards/meanon the console Metrics tab: a steady rise means it is learning; if it plateaus or drops, stop and investigate β do not burn MTU idly. - On FAILED, read the logs first: pull the tail errors with
rl logs; configuration/dependency errors are usually obvious. Note the CLI-side logs cover the orchestration layer only β training-engine / in-function errors do not land in the CLI; use the console job-details Logs tab, or ask the platform for backend logs with the job_id / request_id. - Console details page has five tabs: Details / Trajectories (agent behavior replay + three-dimensional reward analysis) / Metrics (13 chart groups) / Logs / Artifacts (checkpoints).
- Four starter practices: validate the pipeline on minimal data before switching to full data; do not touch hyperparameters on the first run β when tuning, change one variable at a time and run at least
eval_steps Γ 3steps before judging; watch one core metric; read logs first on failure. - Stop-loss: when a confirmed misconfiguration requires aborting,
bl finetune rl cancel --job-id ft-xxx --dry-runβ user confirmation β--yes(cancel is destructive; progress may be lost).
Step 5: Publish & deploy the model
After SUCCEEDED, the last checkpoint is auto-published to "My Models" β manual export is usually unnecessary:
bl finetune checkpoints --job-id ft-xxx # checkpoint list & publication status
# Only needed to publish an intermediate checkpoint (also doable on the console Artifacts tab):
bl finetune export --job-id ft-xxx --checkpoint <ckpt-name> --model-name my-rl-model
bl deploy models --source custom # confirm deployable models & plans
bl deploy list --status RUNNING # reuse check: do not create another billed instance if the same model is already RUNNING
bl deploy text create --model-name <published-model-name> --display-name my-rl-svc --dry-run
# --yes after user confirmation; record output.deployed_model from the response
bl text chat --model <deployed_model> --message "6.6 minus x (3/2) times equals 5.6, solve x."
- Inference
--modelmust usedeployed_modelfrom the deploy response, not the name passed todeploy create --model-nameβ the wrong one 404s withModel not exist. - Invoking immediately after the deployment reaches RUNNING may briefly 404 (server-side state propagation delay); wait a dozen seconds and retry. On persistent 404, first check whether the model name is wrong.
- Deployment plans / billing / pause-delete operations are covered by skill
bailian-finetuneandbl deploy --help; this skill does not duplicate them.
Wrap-up & cleanup
- Delete a job record:
bl finetune rl delete --job-id ft-xxx(destructive; dry-run β user--yes). - Sandbox artifacts: task directories are destroyed automatically when the call ends (same policy for success/failure/timeout). For crash orphans and superseded runtime versions, preview the remove/keep plan with
bl finetune runtime clean --dry-runβ user confirmation β--yes(--ttl-hoursadjusts the orphan threshold, default 24h). The current baseline runtime, theBAILIAN_RL_RUNTIMEdirectory, and the download cache are never touched. - Idle-billing reminder: training fees stop once the RL job reaches a terminal state, but deployment instances (especially mu/ptu) bill while idle β clean up with
bl deploy pause/deletewhen unused.
Common pitfalls (field-verified)
- SLR
REQUIRES_USER_ACTIONis a stop-and-guide signal: the CLI cannot create service-linked roles β guide the user to console authorization, then re-probe;sls-serviceis a static advisory that is always present, never a failure to retry.--authorizewith missing role prerequisites silently does nothing. - Connect-level
EPERM/ENETUNREACHinside an agent β regional network issue: do not loop on mirrors or retries. Readruntime doctor'shost-network-reachabilitydetail, then enable network access in the agent settings or move prepare / submission to a regular terminal (HTTPS_PROXYis honored when set). - Answering with docs + code instead of intake: a triggered training request with missing inputs must produce clarifying questions (Step 0), not a doc-reading spree followed by SDK code samples. Official docs are for resolving a specific blocker mid-flow, never the default first action.
- These commands/flags do not exist: no
bl finetune rl jobssubgroup;rl runhas no top-level--timeout(use--wait-timeout); YAML input is--config-file, not--config(the latter is the global profile flag);--yesis runtime-injected β do not invent confirmation flags. - Hyperparameters cannot be omitted wholesale: SDK type annotations of Optional=None are pass-through only; required constraints live in the server-side validation layer. The only evidence for whether something can be omitted is dry-run + real submission responses, not source annotations.
--requirementslists function business dependencies: they are only read/packaged/uploaded to the FC container and never enter the local sandbox install step. The local SDK version is fixed by the managed runtime baseline;FC_PYPI_LIBis derived and injected automatically by the CLI, invisible to the user β do not export it manually, and do not pip install dashscope on the host for RL.- Function registration failure β training failure:
[2052] Registration failedhappens before the training job is created (no billed training in principle); checkrl listfor FAILED records first. For sandbox write-permission / path errors, check cwd and the absolute-path rules first. - Reward metric-name mismatch is a silent error:
--reward-metrickeys must equal the metric names the Reward function actually returns, verbatim. - watch/logs/get/cancel/delete go host-direct and need no sandbox runtime; only
rl rungoes through the sandbox. An unprepared runtime does not affect query commands. - Server errors pass through verbatim: the CLI does not translate server error codes; a 403
Workspace.AccessDeniedis an account/workspace configuration issue β verify--workspace-idand API key ownership instead of mutating the command and retrying.
Out of scope
These intents do not belong to this skill; here are the correct entry points to avoid misrouting:
| User intent | Correct entry |
|---|---|
| SFT / DPO / CPT / LoRA supervised fine-tuning; audio/image/video fine-tuning | skill bailian-finetune (bl finetune text|audio|image create) |
OPD distillation (pg_opd, teacher_model, pure model distillation) | skill bailian-finetune (bl finetune opd *, host-direct, no sandbox) |
| Training jobs on non-Bailian platforms | Not this skill β use that platform's own tooling |
| Just trying a model / one-off chat | bl text chat (skill bailian-cli) |
| Model selection / recommendation | bl advisor recommend |
| Training quota / usage | bl quota / bl usage (skill bailian-cli) |
references
- bailian-protocol β shared protocol (consent / version pre-flight / auth / attribution / error reporting); read before executing
- skill
bailian-finetune'sreference/finetune.mdβ authoritative flag tables forrl */runtime *(generated); Read it if installed, otherwise promptbl skill init - Official docs: RL training overview Β· RL function development guide Β· RL training configuration & monitoring Β· Observability configuration Β· Model Training Unit
Related skills
Claude API Helper
anthropics
Build, debug, and optimize Claude API applications with caching and model migration support.
Customer Health Scorer
alirezarezvani
Analyze customer accounts to predict churn risk and identify expansion opportunities.
Adaptyv Protein Lab
foryourhealth111-pixel
Submit protein sequences for automated lab testing and validation experiments.
CLAUDE.md Optimizer
daymade
Optimize your CLAUDE.md file for clarity, efficiency, and maintainability.