Conversation
Summary of ChangesHello @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 Highlights
🧠 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
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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-Authorizationheader alongsideAuthorizationin the Python client. - Switch server token extraction to use
Twinkle-Authorization. - Change
resolve_load_path()to return the parent (weights/orsampler_weights/) directory and update model wrappers to pass it through asoutput_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.
| authorization = request.headers.get("Twinkle-Authorization") | ||
| token = authorization[7:] if authorization and authorization.startswith("Bearer ") else authorization | ||
| if not is_token_valid(token): |
There was a problem hiding this comment.
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.
| headers = { | ||
| "X-Ray-Serve-Request-Id": get_request_id(), | ||
| "Authorization": 'Bearer ' + get_api_key(), | ||
| "Twinkle-Authorization": 'Bearer ' + get_api_key(), # For server compatibility |
There was a problem hiding this comment.
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.
| 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 |
| # Get the checkpoint directory parent path (no checkpoint name in the path) | ||
| checkpoint_dir = self.get_ckpt_dir(training_run_id, checkpoint_id).parent | ||
|
|
There was a problem hiding this comment.
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.
No description provided.