Skip to content

Add python API for programmatic access#54

Merged
jwilles merged 60 commits intoVectorInstitute:developfrom
Center-for-AI-Innovation:programmatic_access
Apr 10, 2025
Merged

Add python API for programmatic access#54
jwilles merged 60 commits intoVectorInstitute:developfrom
Center-for-AI-Innovation:programmatic_access

Conversation

@rohan-uiuc
Copy link
Contributor

@rohan-uiuc rohan-uiuc commented Mar 2, 2025

PR Type

Feature

Short Description

  • Add programmatic access through a Python API. This enables developers to integrate model management capabilities directly into their applications and scripts. The API provides methods for listing models, launching models with custom configurations, monitoring model status, retrieving performance metrics, and shutting down models when done.
  • Move shared functionality to a shared package.
  • Add python API docs and update the existing user guide
  • Fix the examples for python API usage

Tests Added

API functionality tests for listing models, launching models, checking status, and waiting for readiness

@rohan-uiuc rohan-uiuc mentioned this pull request Mar 2, 2025
6 tasks
@amrit110
Copy link
Member

amrit110 commented Mar 5, 2025

@rohan-uiuc thanks for the PR. We like the idea of a python API, and the example usage is much appreciated. As a first step, I will make changes to your PR to refactor some stuff (noticed there is some duplication like the ModelConfig, and clean up the lint errors). Stay tuned.

@rohan-uiuc
Copy link
Contributor Author

@amrit110 that sounds good, thank you!

@amrit110 amrit110 added the enhancement New feature or request label Mar 16, 2025
@amrit110 amrit110 requested review from XkunW and jwilles March 16, 2025 20:35
@codecov-commenter
Copy link

codecov-commenter commented Mar 17, 2025

Codecov Report

Attention: Patch coverage is 80.72670% with 122 lines in your changes missing coverage. Please review.

Project coverage is 82.88%. Comparing base (38a4fa7) to head (1e9f8d7).

Files with missing lines Patch % Lines
vec_inf/client/_helper.py 79.50% 50 Missing ⚠️
vec_inf/cli/_cli.py 60.31% 25 Missing ⚠️
vec_inf/cli/_helper.py 73.68% 20 Missing ⚠️
vec_inf/client/_utils.py 82.02% 16 Missing ⚠️
vec_inf/client/api.py 78.43% 11 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop      #54      +/-   ##
===========================================
+ Coverage    79.06%   82.88%   +3.82%     
===========================================
  Files            4       11       +7     
  Lines          554      777     +223     
===========================================
+ Hits           438      644     +206     
- Misses         116      133      +17     
Files with missing lines Coverage Δ
vec_inf/cli/_models.py 100.00% <100.00%> (ø)
vec_inf/cli/_utils.py 100.00% <ø> (+11.49%) ⬆️
vec_inf/client/_config.py 100.00% <ø> (ø)
vec_inf/client/_exceptions.py 100.00% <100.00%> (ø)
vec_inf/client/_models.py 100.00% <100.00%> (ø)
vec_inf/client/_vars.py 100.00% <100.00%> (ø)
vec_inf/client/api.py 78.43% <78.43%> (ø)
vec_inf/client/_utils.py 82.02% <82.02%> (ø)
vec_inf/cli/_helper.py 77.34% <73.68%> (+3.58%) ⬆️
vec_inf/cli/_cli.py 77.50% <60.31%> (-5.66%) ⬇️
... and 1 more

Impacted file tree graph

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@amrit110 amrit110 left a comment

Choose a reason for hiding this comment

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

Very neat refactoring to use helper base classes, and inherit for the api and cli packages.



@dataclass
class ModelInfo:
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think that this state should live in the api namespace. My understanding is that most of them are the responsibility of the launcher and not particularly specific to either a python or cli entrypoint. Can we move them elsewhere?

Error if there was an error retrieving the status.
"""
try:
status_cmd = f"scontrol show job {slurm_job_id} --oneliner"
Copy link
Contributor

Choose a reason for hiding this comment

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

This kind of logic will be duplicated regardless of the entrypoint. Can we contain this logic in the slurm communication class?

from vec_inf.shared._models import ModelType


class APILaunchHelper(LaunchHelper):
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to subclass this or can we push the client-type relevant logic into the client itself and use the same launcher class across all clients?

)
import vec_inf.client._utils as utils
from vec_inf.cli._models import MODEL_TYPE_COLORS, MODEL_TYPE_PRIORITY
from vec_inf.client._config import ModelConfig
Copy link
Contributor

@jwilles jwilles Apr 8, 2025

Choose a reason for hiding this comment

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

I don't think it makes sense to implement inheritance here. Currently we are importing all of the "private" functionality from the client just to make it work in the cli. If the cli just uses the client object then it has a much more abstract ".launch()", ".shutdown()" interface rather than deep coupling with the client implementation.

@XkunW XkunW force-pushed the programmatic_access branch from 19677df to 5ef4e1f Compare April 9, 2025 20:47
MetricsResponseFormatter,
StatusResponseFormatter,
)
from vec_inf.client._models import LaunchOptions, LaunchOptionsDict
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider changing imports from private modules. Should these be exposed explicitly alongside the client if the expectation is that client users will need them (either internal users (cli) or external client users)?

@jwilles jwilles merged commit 9c3a166 into VectorInstitute:develop Apr 10, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

Comments