You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Safe mode breaks Tinker training, loopback-only hosts crash at deploy, checkpoints unusable from stock Tinker SDK #298
I have searched existing issues, and this is a new bug report.
Bug Description
Three problems when running Twinkle 0.5.1 in an isolated container and using it from the stock Tinker SDK (source links at v0.5.1):
Safe mode breaks Tinker training.
With TWINKLE_TRUST_REMOTE_CODE=0, every forward_backward fails with Twinkle does not support Callable or Type inputs in safe mode. The check is check_unsafe on the remote-call path (infra/init.py#L573).
So operators can't turn remote-code trust off, and it defaults to on.
Loopback-only hosts crash at deploy.
Under e.g. docker run --network none, find_node_ip() skips every 127.* address and returns None (utils/network.py#L15-L28).
That None becomes MASTER_ADDR (ray_helper.py#L336), and the deployment fails with TypeError: runtime_env['env_vars'] must be of type Dict[str, str].
Also, .locks is created in the CWD (utils/parallel.py#L9), which fails when the CWD is read-only.
Checkpoints can't be used from the stock Tinker SDK.
save_weights_for_sampler() returns twinkle://... paths, which the unpatched SDK rejects (ValueError: Invalid tinker path). There's also no archive/download endpoint.
name is ignored, and each save deletes the previous sampler weights (checkpoint_manager.py#L241-L285), so earlier returned paths go stale.
How to Reproduce
Set TWINKLE_TRUST_REMOTE_CODE: "0" in the model deployment's env_vars, then call forward_backward(data, "cross_entropy").
Start ray start --head --node-ip-address=127.0.0.1 and twinkle-server launch inside a --network none container.
With tinker==0.16.1, call get_checkpoint_archive_url_from_tinker_path(tc.save_weights_for_sampler(name="x").result().path).
Additional Information
Suggested fixes:
Exempt Twinkle's built-in loss and template classes from check_unsafe.
In find_node_ip(), fall back to 127.0.0.1 (or the Ray node IP), and put .locks under TWINKLE_HOME or the temp dir.
Return tinker://-compatible paths, add the Tinker archive endpoint, and honour name. That would let separate evaluators load trained adapters without patching the SDK.
Environment: twinkle-kit 0.5.1, ray 2.58.0, Ubuntu 24.04 container, tinker 0.16.1.
Activity
inchang-ing commentedon Oct 21, 2026
问题1 的根因定位到 check_unsafe 本身了:src/twinkle/utils/unsafe.py 的 any_callable 把所有 Callable/Type 都当成不能跨 Ray 边界的远程代码,于是 Twinkle 自己的内置 loss/optimizer/scheduler/template 类(twinkle.loss.CrossEntropyLoss 这些)一被当参数传过远程边界(比如 set_loss(loss_cls)、OptimizerGroup 构造)就被拦,safe mode 下没法用内置组件训练。\n\n但这些是包内置符号,worker 端 from twinkle.loss import CrossEntropyLoss 就能重建,本来就不需要 trust_remote_code。修法是 check_unsafe 放行 module 属于 twinkle./twinkle_client./twinkle_agentic.* 的内置符号,仍然拦用户自定义的 lambda/局部类。\n\n注意这跟 #304 不重复:#304 是把 processor 挪出装饰器绕过 check_unsafe,只覆盖 Transformers 的 processor 这一条路;loss/optimizer/scheduler 类过 set_loss/set_optimizer 这些路径没被 #304 碰到,仍会被拦。本修法在 check_unsafe 层放行内置符号,覆盖所有路径。马上提 PR。
Yunnglin commentedon Oct 21, 2026
感谢反馈,更新一下处理进展:训练的 safe-mode 问题已由 #309 解决,loopback 地址问题已由 #301 修复,命名权重保存已由 #300 修复。#311 也已合入,解决只读工作目录问题;#304 已关闭。
我们实跑确认了 Tinker safe-mode 训练,并复跑了 #311 的测试。Tinker 的归档下载接口暂不支持;如需在其他环境使用训练权重,建议先上传到 ModelScope,再从 ModelScope 下载和使用。已支持功能的问题已修复,建议按当前支持范围关闭这个 issue。