Skip to content

feat: add Weaver SDK as third RL training backend#28

Open
void-main wants to merge 4 commits intoaiming-lab:mainfrom
china-qijizhifeng:feature/weaver-backend
Open

feat: add Weaver SDK as third RL training backend#28
void-main wants to merge 4 commits intoaiming-lab:mainfrom
china-qijizhifeng:feature/weaver-backend

Conversation

@void-main
Copy link

@void-main void-main commented Mar 20, 2026

What is Weaver?

Weaver is a cloud-based RL training platform by NexAGI that supports LoRA fine-tuning, similar in scope to Tinker and MinT. It provides synchronous training and sampling APIs with session-managed connections. Like MinT, the nex-weaver SDK is installed separately β€” MetaClaw does not bundle it as a default dependency.

Summary

  • Add Weaver (nex-agi/weaver) as a third RL training backend alongside Tinker and MinT
  • Create metaclaw/weaver_compat.py adapter that wraps Weaver's synchronous API into the async *_async() interface expected by MetaClaw, so no changes needed in trainer.py, api_server.py, data_formatter.py, or rollout.py
  • Register weaver in sdk_backend.py with auto-detection via WEAVER_API_KEY/WEAVER_BASE_URL env vars or URL containing "weaver"
  • Update setup wizard, launcher env seeding, config comments, and all 13 READMEs

Key adapter behaviors

  • EncodedTextChunk β†’ alias for Weaver's ModelInputChunk
  • TensorData.from_torch() β†’ delegates to Weaver's from_array()
  • All *_async() methods β†’ asyncio.to_thread(inner.sync_method, wait=True)
  • Sampling dict responses β†’ SimpleNamespace for attribute access (response.sequences[0].tokens)
  • Unsupported loss functions (ppo, cispo) emit a warning log
  • ServiceClient auto-calls connect() and provides close() for cleanup

Test plan

  • All 12 tests pass in tests/test_sdk_backend.py (7 existing + 5 new)
  • test_resolve_sdk_backend_explicit_weaver β€” explicit backend=weaver resolves correctly
  • test_auto_detects_weaver_from_env β€” WEAVER_API_KEY triggers auto-detection
  • test_auto_detects_weaver_from_url β€” URL containing "weaver" triggers auto-detection
  • test_explicit_weaver_requires_sdk β€” clear error when nex-weaver not installed
  • test_weaver_env_order β€” WEAVER_* env vars have correct priority

πŸ€– Generated with Claude Code

void-main and others added 4 commits March 20, 2026 01:34
Integrate nex-agi/weaver as a new RL backend alongside Tinker and MinT.
A compatibility adapter (weaver_compat.py) wraps Weaver's synchronous
API into the async interface expected by MetaClaw's trainer, so upper-
layer code (trainer.py, api_server.py, data_formatter.py) requires no
changes.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add Weaver configuration examples, install instructions, and
acknowledgment links alongside the existing Tinker and MinT entries
across all 13 README files. Also remove the rl-weaver optional
dependency group from pyproject.toml β€” Weaver SDK is installed
separately, matching the MinT pattern.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The trainer stores `service_client` as a local variable, so the wrapper
(and its inner Weaver ServiceClient) could be GC'd while the training
and sampling clients still reference it β€” causing "ServiceClient is not
connected" errors.

Fix: propagate the inner ServiceClient reference through the wrapper
chain (_TrainingClientWrapper β†’ _SamplingClientWrapper) so it stays
alive. Also remove `__del__` which could close the connection
prematurely.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Weaver's importance_sampling loss function requires an explicit
loss_mask field in loss_fn_inputs. Tinker rejects unknown keys, so
MetaClaw's data_formatter omits it and encodes the information in the
advantages (0.0 for masked positions). The compat layer now derives
loss_mask from advantages before calling forward_backward.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@void-main
Copy link
Author

We verified the training process completes:

CleanShot 2026-03-20 at 11 02 05@2x

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.

1 participant