-
Notifications
You must be signed in to change notification settings - Fork 25.4k
Extract inferece model stats into its own file #134634
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?
Extract inferece model stats into its own file #134634
Conversation
This commit extracts the inner class `ModelStats` of `InferenceFeatureSetUsage` into its own file. There are 2 reasons for doing this: - Allows testing of the `InferenceFeatureSetUsage` class - Introduces a `usage` package under `inference` that can be used to accommodate additional usage data.
Pinging @elastic/ml-core (Team:ML) |
@Override | ||
protected ModelStats mutateInstance(ModelStats modelStats) throws IOException { | ||
ModelStats newModelStats = new ModelStats(modelStats); | ||
newModelStats.add(); | ||
return newModelStats; | ||
} |
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.
This implementation will only test that changes to count
in ModelStats
are correctly accounted for in the equals()
method. Since the equals()
method also considers the service
and taskType
fields, those should be included here too to give full coverage. Something like this maybe:
protected ModelStats mutateInstance(ModelStats modelStats) throws IOException {
String service = modelStats.service();
TaskType taskType = modelStats.taskType();
long count = modelStats.count();
return switch (randomInt(2)) {
case 0 -> new ModelStats(randomValueOtherThan(service, ESTestCase::randomIdentifier), taskType, count);
case 1 -> new ModelStats(service, randomValueOtherThan(taskType, () -> randomFrom(TaskType.values())), count);
case 2 -> new ModelStats(service, taskType, randomValueOtherThan(count, ESTestCase::randomLong));
default -> throw new IllegalArgumentException();
};
}
} | ||
|
||
public static ModelStats createRandomInstance() { | ||
return new ModelStats(randomIdentifier(), TaskType.values()[randomInt(TaskType.values().length - 1)], randomInt(10)); |
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.
Minor nitpick, but the second argument here would be more readable as randomFrom(TaskType.values())
public void add() { | ||
count++; | ||
} |
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.
It's a very minor point, but could there be a test of this method added to ModelStatsTests
?
@DonalEvans I appreciate and agree with all your points. But all the code they refer to was just moved. I would like to keep this |
Absolutely! |
This commit extracts the inner class
ModelStats
ofInferenceFeatureSetUsage
into its own file.There are 2 reasons for doing this:
InferenceFeatureSetUsage
classusage
package underinference
that can be used to accommodate additional usage data.