Skip to content

Fixing ModelLoaderUtils.split() to pass tests #126009

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 3 commits into from
Apr 9, 2025

Conversation

Jason-Whitmore
Copy link
Contributor

The primary changes are to the split() method's functionality. A new variable, numberOfRanges is created to ensure the return list has the correct length. The variables baseChunksPerRange and remainder are now calculated differently to fit the new code structure.

The new code structure completes all but the final range in a single for loop and removes the need for an if statement that adds the second to last range in some cases.

Changes are also made to the method Javadoc to accurately state what the method does.

A good way to test this change is to run:

./gradlew ":x-pack:plugin:ml-package-loader:test" --tests "org.elasticsearch.xpack.ml.packageloader.action.ModelLoaderUtilsTests.testSplitIntoRanges" -Dtests.iters=100000

This test will fail on main, but passes on this PR.

Closes #121799

Prior to these changes, the split method would fail tests. Additionally,
the method had code which could be refactored.

A new variable (numRanges) was introduced to replace the direct usage of numStreams.
The method was refactored to make the code easier to understand. Javadocs were updated.
Tests for this method now pass.
@elasticsearchmachine elasticsearchmachine added v9.1.0 needs:triage Requires assignment of a team area label external-contributor Pull request authored by a developer outside the Elasticsearch team labels Apr 1, 2025
@kingherc kingherc added :ml Machine learning Team:ML Meta label for the ML team labels Apr 1, 2025
@elasticsearchmachine elasticsearchmachine removed the needs:triage Requires assignment of a team area label label Apr 1, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/ml-core (Team:ML)

@prwhelan prwhelan added the >bug label Apr 1, 2025
@prwhelan prwhelan self-assigned this Apr 1, 2025
@prwhelan
Copy link
Member

prwhelan commented Apr 1, 2025

@elasticmachine test this please

@prwhelan
Copy link
Member

prwhelan commented Apr 1, 2025

Thank you for the contribution, and welcome. The code looks good, and I verified the tests pass now.

Can you add a changelog to docs/changelog/126009.yaml that describes the bug fix in 1-3 sentences? Something like Change ModelLoaderUtils.split to return the correct number of chunks

Example: https://github.com/elastic/elasticsearch/blob/main/docs/changelog/125650.yaml

@prwhelan prwhelan self-requested a review April 1, 2025 15:01
@prwhelan
Copy link
Member

prwhelan commented Apr 9, 2025

@elasticmachine test this please

@prwhelan
Copy link
Member

prwhelan commented Apr 9, 2025

@elasticmachine test this please

@prwhelan prwhelan merged commit 36280d2 into elastic:main Apr 9, 2025
17 checks passed
prwhelan pushed a commit to prwhelan/elasticsearch that referenced this pull request Apr 9, 2025
Prior to these changes, the split method would fail tests. Additionally,
the method had code which could be refactored.

A new variable (numRanges) was introduced to replace the direct usage of numStreams.
The method was refactored to make the code easier to understand. Javadocs were updated.
Tests for this method now pass.
elasticsearchmachine pushed a commit that referenced this pull request Apr 9, 2025
Prior to these changes, the split method would fail tests. Additionally,
the method had code which could be refactored.

A new variable (numRanges) was introduced to replace the direct usage of numStreams.
The method was refactored to make the code easier to understand. Javadocs were updated.
Tests for this method now pass.

Co-authored-by: Jason-Whitmore <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug external-contributor Pull request authored by a developer outside the Elasticsearch team :ml Machine learning Team:ML Meta label for the ML team v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[CI] ModelLoaderUtilsTests testSplitIntoRanges failing
4 participants