Skip to content

Conversation

@ChenZiHong-Gavin
Copy link
Collaborator

This PR fixes data type issues in the vLLM wrapper to support fractional GPU allocation and improves token generation reliability with better null handling.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @ChenZiHong-Gavin, 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 focuses on refining the integration with vLLM by addressing data type inconsistencies related to GPU resource allocation and vLLM engine parameters. Additionally, it significantly enhances the robustness and reliability of the token generation process, particularly when retrieving top-k probabilities. These changes contribute to more flexible resource management and more stable interactions with the LLM.

Highlights

  • Fractional GPU Allocation: The num_gpus parameter in init_llm.py now accepts float values, allowing for more granular and flexible allocation of GPU resources.
  • vLLM Engine Argument Type Coercion: Explicit type casting has been added for tensor_parallel_size (to int) and gpu_memory_utilization (to float) when initializing the vLLM AsyncEngineArgs, ensuring correct parameter types for the vLLM engine.
  • Enhanced Token Generation Reliability: The generate_topk_per_token method in vllm_wrapper.py has been improved to robustly handle potential null decoded_token values, strip whitespace from tokens, and return a more structured Token object that includes all top candidates, or an empty list if no candidates are found.
  • Prompt Log Probability Inclusion: The SamplingParams in generate_topk_per_token now includes prompt_logprobs=1, ensuring that log probabilities for prompt tokens are also returned as part of the generation results.
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 correctly addresses data type issues for fractional GPU allocation and adds null handling for improved reliability in the vLLM wrapper. However, I've identified a significant breaking change in the generate_topk_per_token method's return structure. My review includes a suggestion to revert this structural change to maintain API compatibility while retaining the beneficial reliability improvements.

Comment on lines 111 to 127
candidate_tokens = []
for _, logprob_obj in top_logprobs.items():
tok_str = logprob_obj.decoded_token
tok_str = logprob_obj.decoded_token.strip() if logprob_obj.decoded_token else ""
prob = float(math.exp(logprob_obj.logprob))
tokens.append(Token(tok_str, prob))

tokens.sort(key=lambda x: -x.prob)
return tokens
candidate_tokens.append(Token(tok_str, prob))

candidate_tokens.sort(key=lambda x: -x.prob)

if candidate_tokens:
main_token = Token(
text=candidate_tokens[0].text,
prob=candidate_tokens[0].prob,
top_candidates=candidate_tokens
)
return [main_token]
else:
return []
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The structure of the returned value from this function has been changed significantly. Previously, it returned a flat list of candidate Token objects, sorted by probability. The new implementation returns a list containing a single Token object, which in turn contains all candidate tokens in its top_candidates attribute.

This is a breaking change for any consumer of this function that expects a list of all candidates. For example, code that uses len() on the result or iterates over it will now behave differently. This also introduces a potential inconsistency with other BaseLLMWrapper implementations, which might still return a flat list of tokens.

To maintain API compatibility and consistency, I suggest reverting to returning a flat list of candidate tokens, while keeping the beneficial null-safety check for decoded_token.

Suggested change
candidate_tokens = []
for _, logprob_obj in top_logprobs.items():
tok_str = logprob_obj.decoded_token
tok_str = logprob_obj.decoded_token.strip() if logprob_obj.decoded_token else ""
prob = float(math.exp(logprob_obj.logprob))
tokens.append(Token(tok_str, prob))
tokens.sort(key=lambda x: -x.prob)
return tokens
candidate_tokens.append(Token(tok_str, prob))
candidate_tokens.sort(key=lambda x: -x.prob)
if candidate_tokens:
main_token = Token(
text=candidate_tokens[0].text,
prob=candidate_tokens[0].prob,
top_candidates=candidate_tokens
)
return [main_token]
else:
return []
candidate_tokens = []
for _, logprob_obj in top_logprobs.items():
tok_str = logprob_obj.decoded_token.strip() if logprob_obj.decoded_token else ""
prob = float(math.exp(logprob_obj.logprob))
candidate_tokens.append(Token(tok_str, prob))
candidate_tokens.sort(key=lambda x: -x.prob)
return candidate_tokens

@ChenZiHong-Gavin
Copy link
Collaborator Author

Ray makes it possible to use fractional GPUs, like:
image

@ChenZiHong-Gavin ChenZiHong-Gavin merged commit 9fcad68 into main Dec 16, 2025
4 checks passed
@ChenZiHong-Gavin ChenZiHong-Gavin deleted the fix/fix-vllmwrapper branch December 16, 2025 12:06
CHERRY-ui8 pushed a commit to CHERRY-ui8/GraphGen that referenced this pull request Dec 17, 2025
…er (InternScience#117)

* fix: fix data type of num_gpus & generate_topk_per_token of vllmwrapper

* fix: fix lint error
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