[Core]add select by policy for acceleratorclass#518
Conversation
Summary of ChangesHello @pallasathena92, 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 significantly enhances the AcceleratorClass selection mechanism by introducing a flexible, policy-driven approach. Instead of relying solely on explicit naming, users can now define selection policies (e.g., BestFit, Cheapest) along with detailed constraints (memory, features, architecture). This allows for more intelligent and automated resource allocation, optimizing for cost, performance, or specific workload requirements, ultimately improving the efficiency and adaptability of accelerator resource management. 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. 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 a sophisticated policy-based accelerator selection mechanism, which is a great enhancement. The implementation of different policies like BestFit, Cheapest, and MostCapable with detailed scoring logic is well-thought-out. The code is well-structured with helper functions and comprehensive tests. However, I've found a critical issue in the FirstAvailablePolicy implementation that bypasses constraint filtering. I've also identified a few areas for improvement regarding hardcoded values, code duplication, and performance, which I've detailed in the comments. Addressing these points will make the implementation more robust and maintainable.
| cloud.google.com/go/compute/metadata v0.3.0/go.mod h1:zFmK7XCadkQkj6TtorcaGlCW1hT1fIilQDwofLpJ20k= | ||
| github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ= | ||
| github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= | ||
| github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY= |
There was a problem hiding this comment.
Are these changes required
8934f11 to
1b60b4b
Compare
What this PR does
Implement policy-based accelerator class selection with four policies: BestFit, Cheapest, MostCapable, and FirstAvailable
Add constraint-based filtering for accelerator candidates (memory, features, architecture, availability)
Add weighted scoring algorithms for intelligent accelerator selection
Why we need it
There are two ways to specify the ac resources: name and selection policy
Implement Detail
Policy Implementations
BestFit Policy (70% memory + 30% compute)
Penalizes over-provisioning (2x memory = 0.5 score)
Iterative precision fallback with degradation penalty (first precision = 1.0, second = 0.5, third = 0.25)
MinComputePerformanceTFLOPS treated as soft constraint (proportional scoring)
Cheapest Policy
Selects lowest cost accelerator meeting constraints
Priority: spot pricing > on-demand > per-million-tokens
MostCapable Policy (50% memory + 30% bandwidth + 20% TFLOPS)
Normalized scoring across different metric ranges
Prioritizes memory and bandwidth over raw compute for inference workloads
FirstAvailable Policy
Returns first accelerator from runtime's candidate list
Constraint Filtering
MinMemory / MaxMemory bounds
Required features (e.g., NVLink)
Architecture family matching
Excluded accelerator classes
Optional availability check (configurable)
For #517
How to test
Checklist
make testpasses locally