-
Couldn't load subscription status.
- Fork 7.4k
Add hf_infer script for inference using HuggingFace backend #9370
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
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @WinterShiver, 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 new Python script, Highlights
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.
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 new script hf_infer.py for running inference using the HuggingFace backend. The script is well-structured and follows the pattern of similar scripts in the repository.
My review focuses on improving security, configurability, and maintainability. I've pointed out a security risk with trust_remote_code being hardcoded, suggested making torch_dtype and generation parameters more configurable, and noted an unused seed parameter that should be used to ensure reproducibility.
Overall, this is a great addition. Addressing these points will make the script more robust and user-friendly.
| # --- Load model --- | ||
| model = AutoModelForCausalLM.from_pretrained( | ||
| model_name_or_path, | ||
| torch_dtype=torch.bfloat16, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hardcoding torch_dtype to torch.bfloat16 can lead to compatibility issues on hardware that doesn't support it. It's better to make this configurable. Consider adding an infer_dtype argument to the function (e.g., with a default of 'auto') and then dynamically selecting the appropriate torch.dtype based on hardware support (torch.cuda.is_bf16_supported()) or the user's explicit choice.
| gen_cfg = GenerationConfig( | ||
| temperature=temperature, | ||
| top_p=top_p, | ||
| top_k=top_k, | ||
| repetition_penalty=repetition_penalty, | ||
| max_new_tokens=max_new_tokens, | ||
| do_sample=True, | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The GenerationConfig is created manually, which is redundant as get_infer_args already returns a generating_args object with these parameters. This generating_args object is currently unused. To simplify the code and avoid redundancy, you should use the generating_args object directly. This also allows for more flexible generation settings, such as do_sample, to be configured via arguments.
gen_cfg = GenerationConfig(**generating_args.to_dict())
What does this PR do?
Add hf_infer script for inference using HuggingFace backend. This script is developed referring to vllm_infer.
Before submitting