Skip to content

update client server doc#43

Merged
Yunnglin merged 7 commits intodevfrom
add_rl_server
Feb 7, 2026
Merged

update client server doc#43
Yunnglin merged 7 commits intodevfrom
add_rl_server

Conversation

@Yunnglin
Copy link
Copy Markdown
Collaborator

@Yunnglin Yunnglin commented Feb 7, 2026

No description provided.

Copilot AI review requested due to automatic review settings February 7, 2026 09:25
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @Yunnglin, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a significant overhaul of the client-server interaction and its accompanying documentation within the project. It establishes a robust mechanism for automatically generating client-side Python wrappers, thereby reducing manual effort and promoting code consistency. Concurrently, it delivers comprehensive, structured documentation and practical cookbook examples that guide users through both native Twinkle and Tinker-compatible client-server setups, supporting various model backends. These enhancements are designed to elevate the developer experience, clarify architectural patterns, and facilitate easier adoption and integration of the platform.

Highlights

  • Auto-Generated Client Wrappers: Introduced a system for auto-generating client-side Python wrappers for core components like dataloaders, datasets, models, processors, rewards, and samplers. These generated files now include a clear warning against manual modification, streamlining client-side development and ensuring consistency.
  • Comprehensive Client-Server Documentation: Added extensive new documentation covering the client-server architecture, including native Twinkle and Tinker-compatible modes, different model backends (Transformers, Megatron), and detailed usage examples for training and inference. This significantly improves user guidance and understanding of the framework.
  • Cookbook Examples Reorganization and Expansion: Reorganized and expanded the cookbook examples, moving them from a 'legacy' directory to a new 'client' structure. These examples now provide clear, runnable demonstrations for various client-server configurations and workflows, enhancing practical usability.
  • Updated Gitignore for Auto-Generated Files: Modified the .gitignore file to reflect the new auto-generated client directories, ensuring proper version control management for these files.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • .gitignore
    • Removed entries for src/twinkle_client subdirectories, indicating they are now managed differently (likely auto-generated).
  • client_tools/client_generator.py
    • Added an AUTO_GEN_WARNING header to all generated client files.
    • Integrated the AUTO_GEN_WARNING into the generation logic for classes and __init__.py files.
  • cookbook/client/tinker/megatron/lora.py
    • Updated with detailed step-by-step comments for LoRA training and sampling.
    • Removed #%% markers, indicating a shift from interactive notebook-style code.
  • cookbook/client/tinker/megatron/server.py
    • Added new server launch script for Tinker-compatible Megatron backend.
  • cookbook/client/tinker/megatron/server_config.yaml
    • Added new server configuration for Tinker-compatible Megatron backend.
  • cookbook/client/tinker/transformer/lora.py
    • Updated with detailed step-by-step comments for LoRA training.
    • Removed #%% markers.
  • cookbook/client/tinker/transformer/sample.py
    • Added new example script for sampling/inference with Tinker-compatible client.
  • cookbook/client/tinker/transformer/self_congnition.py
    • Updated with detailed step-by-step comments for self-cognition training and evaluation.
    • Removed #%% markers.
  • cookbook/client/tinker/transformer/server.py
    • Added new server launch script for Tinker-compatible Transformers backend.
  • cookbook/client/tinker/transformer/server_config.yaml
    • Added new server configuration for Tinker-compatible Transformers backend.
  • cookbook/client/twinkle/megatron/lora.py
    • Added new LoRA training example using native Twinkle client with Megatron backend.
  • cookbook/client/twinkle/megatron/server.py
    • Added new server launch script for native Twinkle Megatron backend.
  • cookbook/client/twinkle/megatron/server_config.yaml
    • Added new server configuration for native Twinkle Megatron backend.
  • cookbook/client/twinkle/transformer/lora.py
    • Added new LoRA training example using native Twinkle client with Transformers backend.
  • cookbook/client/twinkle/transformer/server.py
    • Added new server launch script for native Twinkle Transformers backend.
  • cookbook/client/twinkle/transformer/server_config.yaml
    • Added new server configuration for native Twinkle Transformers backend.
  • docs/source/index.rst
    • Added a new documentation section for client-server architecture.
  • docs/source/使用指引/服务端和客户端/Tinker兼容客户端.md
    • Added detailed documentation for the Tinker-compatible client.
  • docs/source/使用指引/服务端和客户端/Twinkle客户端.md
    • Added detailed documentation for the native Twinkle client.
  • docs/source/使用指引/服务端和客户端/index.rst
    • Added table of contents for client-server documentation.
  • docs/source/使用指引/服务端和客户端/服务端.md
    • Added detailed documentation for server setup and configuration.
  • docs/source/使用指引/服务端和客户端/概述.md
    • Added an overview of client-server concepts and choices.
  • src/twinkle/sampler/vllm_engine.py
    • Minor formatting changes.
  • src/twinkle/sampler/vllm_sampler.py
    • Changed VLLMLoraWeights().patch(self) to VLLMLoraWeights()(self) for LoRA weight handling.
  • src/twinkle_client/dataloader/init.py
    • Added auto-generated client wrappers for DataLoader.
  • src/twinkle_client/dataloader/dataloader.py
    • Added auto-generated client wrappers for DataLoader.
  • src/twinkle_client/dataset/init.py
    • Added auto-generated client wrappers for Dataset components.
  • src/twinkle_client/dataset/base.py
    • Added auto-generated client wrappers for Dataset components.
  • src/twinkle_client/dataset/iterable_dataset.py
    • Added auto-generated client wrappers for Dataset components.
  • src/twinkle_client/dataset/iterable_packing_dataset.py
    • Added auto-generated client wrappers for Dataset components.
  • src/twinkle_client/dataset/lazy_dataset.py
    • Added auto-generated client wrappers for Dataset components.
  • src/twinkle_client/dataset/packing_dataset.py
    • Added auto-generated client wrappers for Dataset components.
  • src/twinkle_client/model/init.py
    • Added auto-generated client wrappers for MultiLoraTransformersModel.
  • src/twinkle_client/model/multi_lora_transformers.py
    • Added auto-generated client wrappers for MultiLoraTransformersModel.
  • src/twinkle_client/processor/init.py
    • Added auto-generated client wrappers for InputProcessor.
  • src/twinkle_client/processor/base.py
    • Added auto-generated client wrappers for InputProcessor.
  • src/twinkle_client/reward/init.py
    • Added auto-generated client wrappers for MathReward.
  • src/twinkle_client/reward/math_reward.py
    • Added auto-generated client wrappers for MathReward.
  • src/twinkle_client/sampler/init.py
    • Added auto-generated client wrappers for VLLMSampler.
  • src/twinkle_client/sampler/vllm_sampler.py
    • Added auto-generated client wrappers for VLLMSampler.
Activity
  • Yunnglin created this pull request to update client-server documentation.
  • The pull request involves extensive file reorganization, the introduction of new documentation, and the implementation of auto-generated client code.
  • This PR appears to be a significant update to the project's architectural patterns and user guidance.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request significantly improves the documentation and examples for the client-server architecture. It refactors the cookbook examples out of the legacy directory, adding extensive comments and step-by-step instructions to make them much clearer for users. A comprehensive new documentation section has been added, explaining the different client/server modes and backends. The client-side library is now auto-generated and included in the repository, with the generator updated to add warnings against manual edits. The changes are well-structured and greatly enhance the project's usability and maintainability. I have no specific comments as the changes are of high quality.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the client/server documentation and cookbook examples, and starts checking in the auto-generated twinkle_client HTTP wrappers (previously ignored) while removing legacy cookbook artifacts.

Changes:

  • Add auto-generated twinkle_client modules (model/sampler/dataset/dataloader/processor/reward) and their __init__.py exports.
  • Refresh cookbook configs/scripts (new structured examples) and delete legacy cookbook client examples.
  • Update docs to include the new “服务端和客户端” section, and adjust the client generator to prepend an auto-generated warning header.

Reviewed changes

Copilot reviewed 48 out of 50 changed files in this pull request and generated 51 comments.

Show a summary per file
File Description
src/twinkle_client/sampler/vllm_sampler.py New HTTP sampler wrapper (auto-generated).
src/twinkle_client/sampler/init.py Export sampler wrapper.
src/twinkle_client/reward/math_reward.py New HTTP reward wrapper (auto-generated).
src/twinkle_client/reward/init.py Export reward wrapper.
src/twinkle_client/processor/base.py New HTTP input processor wrapper (auto-generated).
src/twinkle_client/processor/init.py Export processor wrapper.
src/twinkle_client/model/multi_lora_transformers.py New HTTP model wrapper (auto-generated).
src/twinkle_client/model/init.py Export model wrapper.
src/twinkle_client/dataset/packing_dataset.py New HTTP dataset wrapper (auto-generated).
src/twinkle_client/dataset/lazy_dataset.py New HTTP dataset wrapper (auto-generated).
src/twinkle_client/dataset/iterable_packing_dataset.py New HTTP iterable dataset wrapper (auto-generated).
src/twinkle_client/dataset/iterable_dataset.py New HTTP iterable dataset wrapper (auto-generated).
src/twinkle_client/dataset/base.py New base HTTP dataset wrapper (auto-generated).
src/twinkle_client/dataset/init.py Export dataset wrappers.
src/twinkle_client/dataloader/dataloader.py New HTTP dataloader wrapper (auto-generated).
src/twinkle_client/dataloader/init.py Export dataloader wrapper.
src/twinkle/sampler/vllm_sampler.py Switch LoRA patching call style to __call__.
src/twinkle/sampler/vllm_engine.py Whitespace-only cleanup.
docs/source/index.rst Add 服务端和客户端 docs index to toctree.
cookbook/legacy/client/twinkle/transformer/server_config.yaml Remove legacy example.
cookbook/legacy/client/twinkle/transformer/server.py Remove legacy example.
cookbook/legacy/client/twinkle/transformer/grpo_lora.py Remove legacy example.
cookbook/legacy/client/twinkle/megatron/server_config.yaml Remove legacy example.
cookbook/legacy/client/twinkle/megatron/server.py Remove legacy example.
cookbook/legacy/client/twinkle/megatron/lora.py Remove legacy example.
cookbook/legacy/client/tinker/transformer/server_config.yaml Remove legacy example.
cookbook/legacy/client/tinker/transformer/server.py Remove legacy example.
cookbook/legacy/client/tinker/transformer/sample.py Remove legacy example.
cookbook/legacy/client/tinker/megatron/server_config.yaml Remove legacy example.
cookbook/legacy/client/tinker/megatron/server.py Remove legacy example.
cookbook/client/twinkle/transformer/server_config.yaml Add documented Twinkle transformers server config example.
cookbook/client/twinkle/transformer/server.py Add documented Twinkle transformers server launcher.
cookbook/client/twinkle/transformer/lora.py Expand comments/documentation in training example.
cookbook/client/twinkle/megatron/server_config.yaml Add documented Twinkle megatron server config example.
cookbook/client/twinkle/megatron/server.py Add documented Twinkle megatron server launcher.
cookbook/client/twinkle/megatron/lora.py Add documented megatron LoRA training example.
cookbook/client/tinker/transformer/server_config.yaml Add documented Tinker-compatible server config example.
cookbook/client/tinker/transformer/server.py Add documented Tinker-compatible server launcher.
cookbook/client/tinker/transformer/self_congnition.py Improve inline documentation and flow in example script.
cookbook/client/tinker/transformer/sample.py Add documented sampling example.
cookbook/client/tinker/transformer/lora.py Expand comments/documentation in training example.
cookbook/client/tinker/megatron/server_config.yaml Add documented Tinker-compatible megatron server config.
cookbook/client/tinker/megatron/server.py Add documented Tinker-compatible megatron server launcher.
cookbook/client/tinker/megatron/lora.py Expand comments/documentation and add sampling step.
client_tools/client_generator.py Prepend AUTO_GEN_WARNING to generated files/__init__.py.
.gitignore Stop ignoring generated src/twinkle_client/* subpackages so they can be committed.
Comments suppressed due to low confidence (1)

cookbook/client/tinker/transformer/self_congnition.py:3

  • Filename and module name use self_congnition (typo). Consider renaming to self_cognition.py to improve discoverability and avoid perpetuating the misspelling in imports/links.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +14 to +17
from twinkle.dataset import Dataset
from twinkle.dataset import DatasetMeta
from .base import Dataset

Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same shadowing issue as other dataset wrappers: importing Dataset from twinkle.dataset and then importing Dataset from .base overwrites the first import. Please drop the unused import or rename one of them to avoid ambiguity.

Copilot uses AI. Check for mistakes.
Comment on lines +16 to +20
from torch.utils.data import IterableDataset

class IterableDataset(IterableDataset):
"""Client wrapper for IterableDataset that calls server HTTP endpoints."""

Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

class IterableDataset(IterableDataset): reuses the same name as the imported base class (torch.utils.data.IterableDataset), which makes the code hard to read/debug and can confuse tooling. Import the torch base class under an alias (e.g., TorchIterableDataset) and subclass that instead.

Copilot uses AI. Check for mistakes.
Comment on lines +36 to +42
- name: models-Qwen2.5-7B-Instruct
route_prefix: /models/Qwen/Qwen2.5-7B-Instruct # REST path for this model
import_path: model
args:
use_megatron: false # Use HuggingFace Transformers (not Megatron)
model_id: "ms://Qwen/Qwen2.5-0.5B-Instruct" # ModelScope model identifier to load
adapter_config:
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The model service name/route refer to Qwen2.5-7B-Instruct, but model_id is set to ms://Qwen/Qwen2.5-0.5B-Instruct. This mismatch is likely to confuse users and can lead to loading a different model than the config name suggests; align the name/route_prefix with the actual model_id (or update the comments to clearly state it's intentionally using 0.5B).

Copilot uses AI. Check for mistakes.
Comment on lines +36 to +42
- name: models-Qwen2.5-7B-Instruct
route_prefix: /models/Qwen/Qwen2.5-7B-Instruct # REST path for this model
import_path: model
args:
use_megatron: true # Use Megatron-LM backend (not HuggingFace)
model_id: "ms://Qwen/Qwen2.5-0.5B-Instruct" # ModelScope model identifier to load
nproc_per_node: 2 # Number of GPU processes per node
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same model naming mismatch as the Transformers config: models-Qwen2.5-7B-Instruct / route prefix indicates 7B, but model_id points to the 0.5B variant. Please make these consistent to avoid misleading configuration/docs.

Copilot uses AI. Check for mistakes.
Comment on lines +726 to 729
sampler_code = AUTO_GEN_WARNING + '''from typing import Any, Optional, List, Dict, Union
import uuid
from twinkle_client.http import TWINKLE_SERVER_URL
from twinkle_client.http import http_post, heartbeat_manager
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sampler_code template defined here generates VLLMSampler.__init__ with a return response.json(). That makes the generated client invalid (constructors must return None) and will also fail when /create returns a non-JSON/empty body. Please adjust the template to not return from __init__ and to only parse JSON for endpoints that actually return JSON.

Copilot uses AI. Check for mistakes.
def __del__(self):
try:
heartbeat_manager.unregister_processor(self.processor_id)
except:
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'except' clause does nothing but pass and there is no explanatory comment.

Copilot uses AI. Check for mistakes.
def __del__(self):
try:
heartbeat_manager.unregister_processor(self.processor_id)
except:
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'except' clause does nothing but pass and there is no explanatory comment.

Copilot uses AI. Check for mistakes.
"""Cleanup: unregister adapter from heartbeat manager."""
try:
heartbeat_manager.unregister_adapter(self.adapter_name)
except:
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'except' clause does nothing but pass and there is no explanatory comment.

Copilot uses AI. Check for mistakes.
def __del__(self):
try:
heartbeat_manager.unregister_processor(self.processor_id)
except:
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'except' clause does nothing but pass and there is no explanatory comment.

Copilot uses AI. Check for mistakes.
try:
if self.adapter_name:
heartbeat_manager.unregister_adapter(self.adapter_name)
except:
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'except' clause does nothing but pass and there is no explanatory comment.

Copilot uses AI. Check for mistakes.
@Yunnglin Yunnglin merged commit 3fe6615 into dev Feb 7, 2026
0 of 4 checks passed
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.

2 participants