Skip to content

fix: update tuning code samples to improve readability #13384

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 21, 2025

Conversation

yishan-pu
Copy link
Contributor

Description

Fixes #

Note: Before submitting a pull request, please open an issue for discussion if you are not associated with Google.

Checklist

@yishan-pu yishan-pu requested review from a team as code owners May 21, 2025 05:03
@product-auto-label product-auto-label bot added the samples Issues that are directly related to samples. label May 21, 2025
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.

Hello @yishan-pu, 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!

Summary of Changes

Hello! Gemini here, providing a summary of this pull request to help everyone get up to speed quickly.

This PR aims to improve the readability of the tuning code samples within the genai/tuning directory. The primary changes involve renaming functions and variables to be more descriptive and adding clarifying comments, including example outputs.

Highlights

  • Improved Readability: The main goal is to make the tuning code samples easier to understand by using clearer names for functions and variables.
  • Function and Variable Renames: Several functions and variables across multiple tuning sample files have been renamed to better reflect their purpose (e.g., test_tuned_endpoint to predict_with_tuned_endpoint, name to tuning_job_name).
  • Added Example Comments: Example response comments have been added to the prediction samples to show users the expected output format.

Changelog

Click here to see the changelog
  • genai/tuning/test_tuning_examples.py
    • Renamed test function test_tuned_endpoint to predict_with_tuned_endpoint.
    • Renamed test function test_checkpoint to predict_with_checkpoints.
  • genai/tuning/tuning_job_get.py
    • Renamed function parameter name to tuning_job_name in get_tuning_job.
    • Renamed local variable tuning_job_name to input_tuning_job_name in the if __name__ == "__main__": block.
    • Updated comments to reflect the parameter name change.
  • genai/tuning/tuning_textgen_with_txt.py
    • Renamed function test_tuned_endpoint to predict_with_tuned_endpoint.
    • Renamed function parameter name to tuning_job_name.
    • Updated comments and the if __name__ == "__main__": block to use the new function and parameter names.
    • Added example response comments.
  • genai/tuning/tuning_with_checkpoints_get_model.py
    • Renamed function parameter name to tuning_job_name in get_tuned_model_with_checkpoints.
    • Renamed local variable tuning_job_name to input_tuning_job_name in the if __name__ == "__main__": block.
    • Updated comments to reflect the parameter name change.
  • genai/tuning/tuning_with_checkpoints_list_checkpoints.py
    • Renamed function parameter name to tuning_job_name in list_checkpoints.
    • Renamed local variable tuning_job_name to input_tuning_job_name in the if __name__ == "__main__": block.
    • Updated comments to reflect the parameter name change.
  • genai/tuning/tuning_with_checkpoints_set_default_checkpoint.py
    • Renamed function parameter name to tuning_job_name in set_default_checkpoint.
    • Renamed local variable tuning_job_name to input_tuning_job_name in the if __name__ == "__main__": block.
    • Updated comments to reflect the parameter name change.
  • genai/tuning/tuning_with_checkpoints_textgen_with_txt.py
    • Renamed function test_checkpoint to predict_with_checkpoints.
    • Renamed function parameter name to tuning_job_name.
    • Updated comments and the if __name__ == "__main__": block to use the new function and parameter names.
    • Added example response comments.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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 issue 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 is currently in preview and 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 to provide feedback.

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.


A name change, small and neat,
Makes the code sample sweet.
Readability's key,
For all eyes to see,
A developer's treat.

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 significantly improves the readability of the tuning code samples. The renaming of functions (e.g., from test_... to predict_...) clarifies their purpose within the context of example code. Parameter names have been made more specific (e.g., name to tuning_job_name), and variables in if __name__ == "__main__": blocks are now more distinct (e.g., input_tuning_job_name). Additionally, comments have been updated for accuracy, and the inclusion of example responses is a helpful touch for users.

These changes are well-executed and consistently applied across all relevant files, including the test file updates. Overall, this is a good enhancement to the samples.

One point to consider from the PR checklist: the item [ ] README is updated to include [all relevant information] is currently unchecked. Please ensure that any README files referencing these sample functions are updated with the new names to maintain documentation accuracy.

Summary of Findings

  • Improved Function Naming: Functions previously named with a test_ prefix (e.g., test_tuned_endpoint, test_checkpoint) have been renamed to use a predict_ prefix (e.g., predict_with_tuned_endpoint, predict_with_checkpoints). This change more accurately reflects their role in the sample code, which is to demonstrate prediction capabilities rather than to serve as unit tests.
  • Enhanced Parameter Clarity: Generic parameter names like name have been replaced with more descriptive names such as tuning_job_name. This improves code comprehension by making the expected input clearer.
  • Clearer Variable Scoping in __main__: In if __name__ == "__main__": blocks, variables used to store user input (e.g., tuning_job_name) have been renamed (e.g., to input_tuning_job_name) to better distinguish them from function parameters, enhancing readability.
  • Updated and Added Code Comments: Code comments have been updated to align with the new function names (e.g., changing "Tests the default checkpoint" to "Predicts with the tuned endpoint"). Additionally, new comments providing example responses have been added, which is beneficial for users running these samples.
  • Consistent Test File Updates: The test file (test_tuning_examples.py) has been correctly updated to call the renamed functions, ensuring that tests remain aligned with the sample code changes.

Merge Readiness

The code changes are well-implemented and significantly improve readability. I recommend merging this pull request once the author has confirmed that any relevant README files are updated to reflect the new function names, as indicated by the unchecked item in the PR checklist. I am not authorized to approve pull requests, so please ensure it undergoes the standard approval process.

@msampathkumar msampathkumar self-assigned this May 21, 2025
Copy link
Member

@msampathkumar msampathkumar left a comment

Choose a reason for hiding this comment

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

LGTM. Nice work @yishan-pu 👍

@msampathkumar msampathkumar merged commit 5003f35 into GoogleCloudPlatform:main May 21, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
samples Issues that are directly related to samples.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants