Skip to content

update load#53

Merged
Yunnglin merged 1 commit intodevfrom
fix_moe
Feb 11, 2026
Merged

update load#53
Yunnglin merged 1 commit intodevfrom
fix_moe

Conversation

@Yunnglin
Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI review requested due to automatic review settings February 11, 2026 12:43
@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 refines the handling of checkpoint loading paths within the twinkle server and client, specifically by ensuring Path objects are correctly managed and converted when necessary. Additionally, it introduces a dedicated Twinkle-Authorization header for API requests, enhancing security and compatibility between the client and server components.

Highlights

  • Refined Checkpoint Loading Paths: Removed unnecessary str() conversions for output_dir in model loading functions, ensuring Path objects are passed directly for better type consistency and handling.
  • Adjusted Path Resolution Logic: Modified resolve_load_path to return the parent directory of a checkpoint and convert it to a POSIX path string, streamlining path management within the system.
  • Updated Authorization Header for Server: Switched the server-side token validation to specifically use a new Twinkle-Authorization header instead of the generic Authorization header for incoming requests.
  • Client-Side Authorization Compatibility: Added the Twinkle-Authorization header to client requests to ensure compatibility with the updated server-side validation mechanism.

🧠 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/tinker/common/megatron_model.py
    • Removed str() conversion when passing resolved.checkpoint_dir to super().load().
  • src/twinkle/server/tinker/common/transformers_model.py
    • Removed str() conversion when passing resolved.checkpoint_dir to super().load().
  • src/twinkle/server/utils/io_utils.py
    • Modified resolve_load_path to return the parent directory of the checkpoint.
    • Converted the checkpoint_dir to a POSIX path string using .as_posix() before returning.
    • Simplified directory existence validation by directly calling .exists() on the Path object.
  • src/twinkle/server/utils/validation.py
    • Updated verify_request_token to retrieve the authorization token from the Twinkle-Authorization header instead of Authorization.
  • src/twinkle_client/init.py
    • Added Twinkle-Authorization header to default client headers for server compatibility.
  • src/twinkle_client/http/http_utils.py
    • Added Twinkle-Authorization header to HTTP utility functions for server compatibility.
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.

@Yunnglin Yunnglin merged commit 475f535 into dev Feb 11, 2026
4 of 8 checks passed
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 introduces two main changes. First, it fixes a bug in the checkpoint loading logic by correctly resolving the checkpoint directory path. This affects megatron_model.py, transformers_model.py, and io_utils.py. Second, it updates the authorization mechanism to use a new Twinkle-Authorization header instead of the standard Authorization header. This change is implemented on both the server (validation.py) and client (__init__.py, http_utils.py) sides, with the client sending both headers for compatibility. The changes are logical and improve the codebase. I have one suggestion regarding code duplication on the client side to improve maintainability.

default_headers = {
"X-Ray-Serve-Request-Id": get_request_id(),
"Authorization": 'Bearer ' + api_key,
"Twinkle-Authorization": 'Bearer ' + api_key, # For server compatibility
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

With the addition of the Twinkle-Authorization header, the logic for constructing default headers is now duplicated between this file and src/twinkle_client/http/http_utils.py. To improve maintainability and ensure consistency, consider centralizing this header creation logic. For example, the _build_headers function in http_utils.py could be enhanced and used in both locations.

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 Twinkle’s auth header handling and adjusts checkpoint load path resolution so model load() receives the expected output_dir root rather than a specific checkpoint subdirectory.

Changes:

  • Add Twinkle-Authorization header alongside Authorization in the Python client.
  • Switch server token extraction to use Twinkle-Authorization.
  • Change resolve_load_path() to return the parent (weights/ or sampler_weights/) directory and update model wrappers to pass it through as output_dir.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/twinkle_client/http/http_utils.py Adds Twinkle-Authorization header to standard client requests.
src/twinkle_client/__init__.py Adds Twinkle-Authorization to default headers for the tinker-compat client.
src/twinkle/server/utils/validation.py Reads token from Twinkle-Authorization in request middleware.
src/twinkle/server/utils/io_utils.py Updates resolve_load_path() to return the checkpoint root directory (weights/ / sampler_weights/).
src/twinkle/server/tinker/common/transformers_model.py Uses updated resolved.checkpoint_dir directly when calling load().
src/twinkle/server/tinker/common/megatron_model.py Uses updated resolved.checkpoint_dir directly when calling load().

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

Comment on lines +25 to 27
authorization = request.headers.get("Twinkle-Authorization")
token = authorization[7:] if authorization and authorization.startswith("Bearer ") else authorization
if not is_token_valid(token):
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

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

verify_request_token now only checks Twinkle-Authorization. This breaks existing clients sending the standard Authorization header and can lead to token=None being passed into custom is_token_valid implementations. Consider accepting both headers (e.g., prefer Twinkle-Authorization if present, else fall back to Authorization) and returning a clear 401/403 when neither header is provided. Also update the docstring which still says it reads Authorization.

Copilot uses AI. Check for mistakes.
Comment on lines 17 to +20
headers = {
"X-Ray-Serve-Request-Id": get_request_id(),
"Authorization": 'Bearer ' + get_api_key(),
"Twinkle-Authorization": 'Bearer ' + get_api_key(), # For server compatibility
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

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

get_api_key() is called twice when building headers. Store it in a local variable and reuse it for both Authorization and Twinkle-Authorization to avoid repeated context/env lookups and ensure both headers are always identical.

Suggested change
headers = {
"X-Ray-Serve-Request-Id": get_request_id(),
"Authorization": 'Bearer ' + get_api_key(),
"Twinkle-Authorization": 'Bearer ' + get_api_key(), # For server compatibility
api_key = get_api_key()
headers = {
"X-Ray-Serve-Request-Id": get_request_id(),
"Authorization": 'Bearer ' + api_key,
"Twinkle-Authorization": 'Bearer ' + api_key, # For server compatibility

Copilot uses AI. Check for mistakes.
Comment on lines +915 to 917
# Get the checkpoint directory parent path (no checkpoint name in the path)
checkpoint_dir = self.get_ckpt_dir(training_run_id, checkpoint_id).parent

Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

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

resolve_load_path now returns the parent of get_ckpt_dir(...) (the weights/ or sampler_weights/ directory) rather than the specific checkpoint directory. This behavior is likely correct for callers that do os.path.join(output_dir, name), but the variable name checkpoint_dir and surrounding docstrings/comments become misleading. Please clarify the contract (e.g., document that this is the "output_dir" root) to avoid future misuse.

Copilot uses AI. Check for mistakes.
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