Skip to content

fix: keep runtime locks outside the working directory - #311

Merged
Yunnglin merged 1 commit into
modelscope:mainfrom
Liuchenbing-2026:fix/readonly-runtime-locks-20261013
Oct 21, 2026
Merged

Yunnglin merged 1 commit into
modelscope:mainfrom
Liuchenbing-2026:fix/readonly-runtime-locks-20261013

Conversation

@Liuchenbing-2026

Copy link
Copy Markdown
Contributor

PR type

  • Bug Fix
  • New Feature
  • Document Updates
  • More Models or Datasets Support

PR information

Importing twinkle.utils.parallel currently creates .locks in the working directory, causing PermissionError when that directory is read-only.

Move runtime locks to an absolute path under TWINKLE_HOME, defaulting to <tempdir>/twinkle/<user>/.locks, and create the directory only when a processing lock or one-shot claim is used. Processes sharing this runtime directory coordinate across different working directories. Multi-host runs should set TWINKLE_HOME to a writable shared filesystem.

Addresses the read-only working-directory lock problem in #298. Add filesystem and subprocess regressions for both default/custom runtime paths, import without directory creation, cross-directory locking and claims, session rollover, and exception cleanup.

Experiment results

Validated on macOS arm64, CPython 3.12.13, datasets 5.1.0, filelock 4.1.1, and pytest 9.1.1:

  • The same regression tests on base ec8fd1f0660b09ed60938d02d2439533a5aa5c65: 5 failed, 1 passed, including real read-only-directory PermissionError failures.
  • On head 0de02dfe4103ef9033befdc72f90d1e4a1ce93b3: 6 passed, no skips.
  • All applicable changed-file pre-commit hooks passed.
python -m pytest tests/utils/test_parallel.py -q
pre-commit run --files src/twinkle/utils/parallel.py tests/utils/test_parallel.py

The tests load the real utility module directly and use real FileLock/filesystem/subprocess behavior. Read-only permission cases skip for root or non-POSIX environments. Validation covers this CPU utility; full training/SDK integration and hardware tests remain untested.

AI assistance: Codex assisted with the implementation and regression tests.

Use a per-user temporary directory, with TWINKLE_HOME as an override,
and create it only when locks are used. Add real filesystem and
cross-process regressions for read-only working directories.

Signed-off-by: liuchenbing <[email protected]>
@Liuchenbing-2026

Copy link
Copy Markdown
Contributor Author

@Yunnglin could you please review this focused fix for the read-only working-directory part of #298?

I reran the committed regression tests against the original base (ec8fd1f0660b09ed60938d02d2439533a5aa5c65), current main (9953ea1ebbbdbe59c3831702157d3c147ca0ee26), and this PR's unchanged head (0de02dfe4103ef9033befdc72f90d1e4a1ce93b3). The tests use the actual utility source, filesystem permissions, and separate processes:

Revision Result
Original base 5 failed, 1 passed
Current main 5 failed, 1 passed
PR head 6 passed, no skips

Rechecked on Linux/aarch64 with Python 3.12.13 and datasets 4.8.4, running as an unprivileged user so the read-only-directory cases really exercise PermissionError. Coverage includes lazy initialization, default/custom runtime directories, cross-directory locking/claims, session rollover, and exception cleanup.

This addresses only the lock-directory subproblem, not all of #298. Multi-host deployment and the full Tinker training workflow were not exercised in this rerun. Thanks!

@Yunnglin

Copy link
Copy Markdown
Collaborator

建议合入。本次独立复跑确认,它修复的是 #298 中仍存在的只读工作目录/跨 CWD 锁协调问题。

使用本 PR 已提交的同一套 tests/utils/test_parallel.py,仅通过测试加载入口切换被测 MODULE_PATH,不修改两边生产源码。在 Linux、Python 3.12、非 root 身份(uid=65534)下运行,因此只读权限用例没有被跳过:

被测源码 结果
main 96dab686dc5eb33d1eb1ddab999e6dc98801be21 5 failed, 1 passed
本 PR head 0de02dfe4103ef9033befdc72f90d1e4a1ce93b3 6 passed, 0 skipped

main 的两个只读目录用例都在导入时触发 PermissionError: [Errno 13] Permission denied: '.locks';导入惰性、跨目录 claim 和跨目录锁等待用例也失败。PR head 六项均通过,包括默认/自定义 runtime 目录、导入不创建目录、跨 CWD 锁与 claim、session rollover 和异常后释放。

另外用真实只读挂载 /sys 作为 CWD 导入 main,复现了 OSError: [Errno 30] Read-only file system: '.locks'。当前 main 的 parallel.py 与本 PR 原始 base 在该文件上没有差异,因此不是已被 main 修掉的旧问题。

合入仍需满足仓库 CI/审批门禁;核对时常规 lint 和 unittest 已成功,NPU unittest 仍在排队。多主机若需要协调共享缓存,应配置同一可写共享 TWINKLE_HOME,默认临时目录不是跨主机锁服务。

本 PR 仅解决 lock-directory 子项,不包含 stock Tinker checkpoint URI/archive 下载兼容性。建议保留 #298,直到该剩余问题也完成修复与验收。

@Yunnglin
Yunnglin merged commit b6277bc into modelscope:main Oct 21, 2026
2 of 3 checks passed
tastelikefeet added a commit that referenced this pull request Nov 28, 2026
main carried 17 commits (#311..#291) over merge-base 96dab68. v5 had already ported
everything up to #312 (a4ddc3b) and moved server/client to twinkle_cs, so:

- server/client (src/twinkle/server, twinkle_cs/*, tests/server, tests/twinkle_client):
  kept the v5 tree; the legacy src/twinkle/server path and the old ci_container_test.sh
  stay removed on v5.
- loss: #291 detached DFT weights, #335 Liger CE contract (delegates micro_batch_scale /
  batch_normalizer to CrossEntropyLoss), #334 chunked CE comments, #336 InfoNCE tests.
- model: #343 Torch.empty_cache (auto-merged), #385 fused_lm_rl ported onto the v5 task
  registry (processor/tasks.py + model/tasks.py FusedRL + transformers postprocess),
  #386 NPU fused CE fast path in selective_log_softmax.
- twinkle_agentic: #345 check kinds (hidden_python / sql_query / answer_one_of /
  answer_number / web_receipt / lean) adapted to the episode-scoped Env interface;
  AgenticChallenger gains the _verify_check / _proposal_reward hooks.

Known: cookbook/rsi and tests/cookbook/rsi (#345) are written against main's stateless
Env / AgenticChallenger API and do not run on v5 yet.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants