Skip to content

Refact server#111

Draft
Yunnglin wants to merge 2 commits intomainfrom
refact_server
Draft

Refact server#111
Yunnglin wants to merge 2 commits intomainfrom
refact_server

Conversation

@Yunnglin
Copy link
Collaborator

PR type

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

PR information

Write the detail information belongs to this PR.

Experiment results

Paste your experiment result here(if needed).

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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 architectural refactoring of the server, merging the functionalities of Tinker and Twinkle into a single, unified system. The changes aim to enhance maintainability and reduce redundancy by centralizing common utilities, establishing a dedicated gateway for client API routing, and modularizing the server's core components into distinct, manageable packages. This new structure simplifies deployment, improves code organization, and sets the foundation for future development.

Highlights

  • Unified Server Architecture: The server has been refactored to unify the previously separate Tinker and Twinkle server implementations into a single, cohesive Ray Serve deployment.
  • Centralized Common Utilities: Shared modules such as datum, io_utils, router, and serialize have been moved to a new src/twinkle/server/common directory, reducing code duplication.
  • Dedicated Gateway Service: A new src/twinkle/server/gateway service has been introduced to act as a unified entry point, handling API routing for both Tinker and Twinkle clients.
  • Modularized Application Components: Core application components (model, processor, and sampler) are now organized into distinct packages, each with dedicated Tinker and Twinkle API handlers.
  • Simplified Server Launcher: The ServerLauncher has been updated to remove the server_type argument, streamlining server configuration and reflecting the single server approach.
  • Client-Side Type Definitions: Explicit Pydantic models have been introduced in twinkle_client/types to define clear API request/response structures for server, model, processor, sampler, and training-related functionalities.

🧠 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
  • src/twinkle/server/main.py
    • Simplified command-line arguments and usage examples by removing server type specific options.
  • src/twinkle/server/common/init.py
    • Added new initialization file for the common utilities package.
  • src/twinkle/server/common/datum.py
    • Renamed from src/twinkle/server/tinker/common/datum.py.
  • src/twinkle/server/common/io_utils.py
    • Added new file, merging functionalities from previous Tinker and Twinkle IO utilities.
  • src/twinkle/server/common/router.py
    • Renamed from src/twinkle/server/tinker/common/router.py.
  • src/twinkle/server/common/serialize.py
    • Renamed from src/twinkle/server/twinkle/common/serialize.py.
  • src/twinkle/server/gateway/init.py
    • Added new initialization file for the gateway package.
  • src/twinkle/server/gateway/proxy.py
    • Renamed from src/twinkle/server/tinker/proxy.py and updated for unified routing with Tinker endpoints prefixed.
  • src/twinkle/server/gateway/server.py
    • Added new file, implementing the unified gateway server for both Tinker and Twinkle clients.
  • src/twinkle/server/gateway/tinker_gateway_handlers.py
    • Added new file, containing Tinker-specific gateway handlers.
  • src/twinkle/server/gateway/twinkle_gateway_handlers.py
    • Added new file, containing Twinkle-specific gateway handlers.
  • src/twinkle/server/launcher.py
    • Updated ServerLauncher to remove the server_type argument and simplify builder resolution for a unified server.
  • src/twinkle/server/model/init.py
    • Added new initialization file for the model package.
  • src/twinkle/server/model/app.py
    • Added new file, implementing the unified model management application.
  • src/twinkle/server/model/backends/init.py
    • Renamed from src/twinkle/server/twinkle/common/__init__.py.
  • src/twinkle/server/model/backends/common.py
    • Renamed from src/twinkle/server/tinker/common/compat_base.py and updated for shared backend model helpers.
  • src/twinkle/server/model/backends/megatron_model.py
    • Renamed from src/twinkle/server/tinker/common/megatron_model.py and updated imports.
  • src/twinkle/server/model/backends/transformers_model.py
    • Renamed from src/twinkle/server/tinker/common/transformers_model.py and updated to handle both Tinker and Twinkle I/O.
  • src/twinkle/server/model/tinker_handlers.py
    • Added new file, containing Tinker-compatible model handlers.
  • src/twinkle/server/model/twinkle_handlers.py
    • Added new file, containing Twinkle-native model handlers.
  • src/twinkle/server/processor/init.py
    • Added new initialization file for the processor package.
  • src/twinkle/server/processor/app.py
    • Renamed from src/twinkle/server/twinkle/processor.py and updated for unified processor management.
  • src/twinkle/server/sampler/init.py
    • Added new initialization file for the sampler package.
  • src/twinkle/server/sampler/app.py
    • Added new file, implementing the unified sampler management application.
  • src/twinkle/server/sampler/tinker_handlers.py
    • Added new file, containing Tinker-compatible sampler handlers.
  • src/twinkle/server/sampler/twinkle_handlers.py
    • Added new file, containing Twinkle-native sampler handlers.
  • src/twinkle/server/tinker/init.py
    • Removed the Tinker server package.
  • src/twinkle/server/tinker/common/init.py
    • Removed the Tinker common utilities package.
  • src/twinkle/server/tinker/common/io_utils.py
    • Removed the Tinker-specific IO utilities.
  • src/twinkle/server/tinker/model.py
    • Removed the Tinker model management server.
  • src/twinkle/server/tinker/sampler.py
    • Removed the Tinker sampler server.
  • src/twinkle/server/tinker/server.py
    • Removed the Tinker-compatible server implementation.
  • src/twinkle/server/twinkle/init.py
    • Removed the Twinkle server package.
  • src/twinkle/server/twinkle/common/io_utils.py
    • Removed the Twinkle-specific IO utilities.
  • src/twinkle/server/twinkle/common/transformers_model.py
    • Removed the Twinkle-specific Transformers model compatibility wrapper.
  • src/twinkle/server/twinkle/model.py
    • Removed the Twinkle model management server.
  • src/twinkle/server/twinkle/sampler.py
    • Removed the Twinkle sampler server.
  • src/twinkle/server/twinkle/server.py
    • Removed the Twinkle REST API server.
  • src/twinkle/server/utils/task_queue.py
    • Added a new schedule_task_and_wait method for synchronous task execution.
  • src/twinkle_client/http/http_utils.py
    • Updated import path for serialize_object to reflect the new common utilities location.
  • src/twinkle_client/manager.py
    • Updated import paths for Checkpoint, Cursor, and TrainingRun to use the new client-side type definitions.
  • src/twinkle_client/types/init.py
    • Added new initialization file for the client types package.
  • src/twinkle_client/types/model.py
    • Added new file, defining Pydantic models for Twinkle model management endpoints.
  • src/twinkle_client/types/processor.py
    • Added new file, defining Pydantic models for Twinkle processor endpoints.
  • src/twinkle_client/types/sampler.py
    • Added new file, defining Pydantic models for Twinkle sampler endpoints.
  • src/twinkle_client/types/server.py
    • Added new file, defining Pydantic models for Twinkle server health and error endpoints.
  • src/twinkle_client/types/training.py
    • Added new file, defining Pydantic models for Twinkle training runs and checkpoints.
Activity
  • The author, Yunnglin, has initiated a significant refactoring effort to unify the server architecture.
  • The changes involve extensive file reorganization, including renaming, moving, and creating new files to establish a modular and centralized server structure.
  • The server launcher has been updated to reflect the new single server type, simplifying its configuration.
  • New client-side Pydantic models have been introduced to standardize API request and response structures, improving clarity and consistency.
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
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 introduces a significant and well-executed refactoring of the server architecture. By unifying the tinker and twinkle server implementations, it greatly improves code structure, reduces duplication, and enhances maintainability. Key improvements include a unified gateway, model, and sampler application, consolidation of common utilities, and decoupling of client-side data types. The new structure is much cleaner and provides a solid foundation for future development. I've added a couple of minor suggestions to improve code style by moving inline imports to the top of their respective files.

Note: Security Review did not run due to the size of the PR.

Comment on lines +121 to +122
from twinkle.server.common.io_utils import create_checkpoint_manager
checkpoint_manager = create_checkpoint_manager(token, client_type='tinker')
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

For better code style and maintainability, it's recommended to move this import statement to the top of the file. Inline imports can obscure dependencies and may introduce slight performance overhead if called frequently.

Suggested change
from twinkle.server.common.io_utils import create_checkpoint_manager
checkpoint_manager = create_checkpoint_manager(token, client_type='tinker')
checkpoint_manager = create_checkpoint_manager(token, client_type='tinker')

Comment on lines +121 to +122
from twinkle.server.common.io_utils import create_checkpoint_manager
checkpoint_manager = create_checkpoint_manager(token, client_type='tinker')
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

For better code style and maintainability, it's recommended to move this import statement to the top of the file. Inline imports can obscure dependencies and may introduce slight performance overhead if called frequently.

Suggested change
from twinkle.server.common.io_utils import create_checkpoint_manager
checkpoint_manager = create_checkpoint_manager(token, client_type='tinker')
checkpoint_manager = create_checkpoint_manager(token, client_type='tinker')

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