Skip to content

[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

Merged
merged 1 commit into from
Jul 1, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions llvm/lib/Analysis/DevelopmentModeInlineAdvisor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ManagedStatic.h"

#include <vector>
#include <optional>
#include <vector>

using namespace llvm;

Expand Down Expand Up @@ -260,9 +260,8 @@ static const std::vector<TensorSpec> TrainingOnlyFeatures{

static const std::vector<TensorSpec> getInputFeatures() {
std::vector<TensorSpec> InputSpecs;
Copy link
Preview

Copilot AI Jul 1, 2025

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.

Suggested change
std::vector<TensorSpec> InputSpecs;
std::vector<TensorSpec> InputSpecs;
InputSpecs.reserve(FeatureMap.size() + TrainingOnlyFeatures.size());

Copilot uses AI. Check for mistakes.

for (size_t I = 0; I < NumberOfFeatures; ++I)
InputSpecs.push_back(
TensorSpec(TFFeedPrefix + FeatureMap[I].name(), FeatureMap[I]));
for (const auto &Feature : FeatureMap)
InputSpecs.push_back(TensorSpec(TFFeedPrefix + Feature.name(), Feature));
append_range(InputSpecs, TrainingOnlyFeatures);
return InputSpecs;
}
Expand Down Expand Up @@ -299,7 +298,8 @@ void TrainingLogger::logInlineEvent(const InlineEvent &Event,
const MLModelRunner &ModelRunner) {
L->startObservation();
size_t CurrentFeature = 0;
for (; CurrentFeature < NumberOfFeatures; ++CurrentFeature)
size_t FeatureMapSize = FeatureMap.size();
for (; CurrentFeature < FeatureMapSize; ++CurrentFeature)
L->logTensorValue(CurrentFeature,
reinterpret_cast<const char *>(
ModelRunner.getTensorUntyped(CurrentFeature)));
Expand Down
Loading