Skip to content
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

Prediction API #5

Merged
merged 37 commits into from
May 1, 2024
Merged

Prediction API #5

merged 37 commits into from
May 1, 2024

Conversation

cmelone
Copy link
Collaborator

@cmelone cmelone commented Jan 24, 2024

This PR implements an endpoint that accepts the following payload via a GET request to /v1/allocation:

{
    "package": {
        "name": "string",
        "version": "string",
        "variants": "string"
    },
    "compiler": {
        "name": "string",
        "version": "string"
    }
}

It will also accept an array of these dictionaries.

The program will then search for 4 ≤ x ≤ 5 samples with the following covariates (in priority order):

  1. ("pkg_name", "pkg_version", "compiler_name", "compiler_version")
  2. ("pkg_name", "compiler_name", "compiler_version")
  3. ("pkg_name", "pkg_version", "compiler_name")
  4. ("pkg_name", "compiler_name")
  5. ("pkg_name", "pkg_version")
  6. ("pkg_name",)

We've chosen this order after running simulations of this prediction algorithm and finding that (1) is the best predictor of resource usage.

After collecting the sample, the program returns a mean of past CPU and memory usage to suggest an appropriate k8s allocation. For the moment, we are only targeting requests.

Additionally, we have implemented a safeguard ensuring that the requests will not be set below what is currently allocated for each package. spack/spack#42351, which was merged a few days ago, increases the allocation for many packages (based on max memory per package, rather than mean as we do here). I am hypothesizing that this will likely render many of the predictions futile, but it's still a good opportunity for a Gantry trial run.

I'm looking for any ways to improve the code or make it more concise!

@cmelone cmelone added the feature New feature or request label Jan 24, 2024
@cmelone cmelone self-assigned this Jan 24, 2024
@cmelone cmelone changed the base branch from add/collection-func to develop January 30, 2024 04:41
@cmelone cmelone changed the base branch from develop to add/collection-func January 30, 2024 04:41
@cmelone cmelone force-pushed the add/predict branch 2 times, most recently from dcb99d4 to aab0a7d Compare January 31, 2024 07:28
@cmelone cmelone changed the base branch from add/collection-func to add/first-docs February 1, 2024 05:01
@cmelone cmelone changed the base branch from add/first-docs to add/collection-func February 1, 2024 05:02
@cmelone cmelone marked this pull request as ready for review February 1, 2024 05:19
@cmelone cmelone requested a review from alecbcs February 1, 2024 05:22
Copy link
Member

@alecbcs alecbcs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking really good! Just a few initial impressions and a small suggestion.

gantry/views.py Outdated Show resolved Hide resolved
gantry/views.py Outdated Show resolved Hide resolved
gantry/util/k8s.py Outdated Show resolved Hide resolved
gantry/routes/prediction/prediction.py Outdated Show resolved Hide resolved
Base automatically changed from add/collection-func to develop February 12, 2024 19:19
@cmelone cmelone requested a review from alecbcs February 16, 2024 00:20
@cmelone cmelone force-pushed the add/predict branch 2 times, most recently from 790dbdf to 87eebb8 Compare March 7, 2024 21:08
@cmelone cmelone requested a review from alecbcs March 7, 2024 21:11
@github-actions github-actions bot added the docs Improvements or additions to documentation label Apr 24, 2024
gantry/routes/prediction/prediction.py Outdated Show resolved Hide resolved
gantry/routes/prediction/prediction.py Outdated Show resolved Hide resolved
cmelone and others added 26 commits April 25, 2024 16:46
Rather than grabbing the 4-5 rows that match based on other params (name, version for both pkg and compiler) and then filtering by variant, these queries are now split up into two. The program will first try to do an exact match on variants. If that doesn't work, it'll try to match based on expensive variants. This increases the amount of queries being done, but is a more robust system and will result in more matches.
we have two options for accepting multiple predictions:

1) instructing the client to send a request for each prediction
2) allowing the client to pass a list of specs to predict for

the second option presents a problem when we get into the weeds
of GET request length limits. since specs can vary widely in
length when running json.dumps() on them, it would be difficult
to either instruct the client to limit their length, or to
somehow validate it.

when we were allowing bulk prediction in one GET request,
it was handled through an asyncio.gather() call. this approach
is approximately 2x faster than individual HTTP requests when
testing 5000 consecutive calls to the API (4s vs 8s). In this case,
8 seconds is not very long so it's not a problem, but we can revisit this
in the future if we run into performance issues.
Co-authored-by: Alec Scott <[email protected]>
Copy link
Member

@alecbcs alecbcs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Thanks @cmelone!

@alecbcs alecbcs merged commit 547f80a into develop May 1, 2024
5 checks passed
@alecbcs alecbcs deleted the add/predict branch May 1, 2024 00:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Improvements or additions to documentation feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants