-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[MLGO] Fix feature iteration using FeatureMap.size() instead of NumberOfFeatures #146436
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
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
|
@llvm/pr-subscribers-llvm-analysis Author: S. VenkataKeerthy (svkeerthy) ChangesDue to the changes made in #143479, size of Full diff: https://github.com/llvm/llvm-project/pull/146436.diff 1 Files Affected:
diff --git a/llvm/lib/Analysis/DevelopmentModeInlineAdvisor.cpp b/llvm/lib/Analysis/DevelopmentModeInlineAdvisor.cpp
index e7e8f2ac1ff25..fcaa32750b7ab 100644
--- a/llvm/lib/Analysis/DevelopmentModeInlineAdvisor.cpp
+++ b/llvm/lib/Analysis/DevelopmentModeInlineAdvisor.cpp
@@ -27,8 +27,8 @@
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ManagedStatic.h"
-#include <vector>
#include <optional>
+#include <vector>
using namespace llvm;
@@ -260,7 +260,7 @@ static const std::vector<TensorSpec> TrainingOnlyFeatures{
static const std::vector<TensorSpec> getInputFeatures() {
std::vector<TensorSpec> InputSpecs;
- for (size_t I = 0; I < NumberOfFeatures; ++I)
+ for (size_t I = 0; I < FeatureMap.size(); ++I)
InputSpecs.push_back(
TensorSpec(TFFeedPrefix + FeatureMap[I].name(), FeatureMap[I]));
append_range(InputSpecs, TrainingOnlyFeatures);
@@ -299,7 +299,7 @@ void TrainingLogger::logInlineEvent(const InlineEvent &Event,
const MLModelRunner &ModelRunner) {
L->startObservation();
size_t CurrentFeature = 0;
- for (; CurrentFeature < NumberOfFeatures; ++CurrentFeature)
+ for (; CurrentFeature < FeatureMap.size(); ++CurrentFeature)
L->logTensorValue(CurrentFeature,
reinterpret_cast<const char *>(
ModelRunner.getTensorUntyped(CurrentFeature)));
|
a3cdb1b to
e231124
Compare
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.
Pull Request Overview
This PR replaces hardcoded NumberOfFeatures iterations with dynamic FeatureMap.size() and modernizes loops accordingly.
- Switched to a range-based loop in
getInputFeatures - Cached
FeatureMap.size()for iteration inlogInlineEvent - Adjusted include ordering
Comments suppressed due to low confidence (2)
llvm/lib/Analysis/DevelopmentModeInlineAdvisor.cpp:263
- [nitpick] The loop variable
Featureis capitalized like a type and may shadow other symbols; consider renaming it tofeatureor a more descriptive name such asfeatureSpec.
for (const auto &Feature : FeatureMap)
llvm/lib/Analysis/DevelopmentModeInlineAdvisor.cpp:263
- Now that
NumberOfFeaturesis no longer used, its definition can be removed from the codebase to avoid dead code and potential confusion.
for (const auto &Feature : FeatureMap)
| TensorSpec::createSpec<int32_t>(TFFeedPrefix + "step_type", {1})}; | ||
|
|
||
| static const std::vector<TensorSpec> getInputFeatures() { | ||
| std::vector<TensorSpec> InputSpecs; |
Copilot
AI
Jul 1, 2025
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.
[nitpick] Reserve the expected capacity for InputSpecs (e.g., InputSpecs.reserve(FeatureMap.size() + TrainingOnlyFeatures.size());) to avoid multiple reallocations during push_back.
| std::vector<TensorSpec> InputSpecs; | |
| std::vector<TensorSpec> InputSpecs; | |
| InputSpecs.reserve(FeatureMap.size() + TrainingOnlyFeatures.size()); |
Merge activity
|

Due to the changes made in #143479, size of
FeatureMapreflects the number of features used. Hence replacingNumberOfFeatureswithFeatureMap.size()in theDevelopmentModeInlineAdvisor.