GitLab MLOps Python Client
A Python client for integrating GitLab's MLOps features, specifically designed to leverage GitLab's experiment tracking and model registry capabilities. This client simplifies the management of machine learning workflows by combining MLflow's flexibility with GitLab's powerful MLOps tools.
Features
- GitLab Experiment Tracking: Easily track machine learning experiments within GitLab.
- Model Registry Integration: Register and manage models in GitLab's model registry.
- Experiment Management: Create and manage experiments directly from the client.
- Run Tracking: Initiate and monitor training runs with ease.
- Model Lifecycle Management: Promote runs to model versions effortlessly.
Feedback
The MLOPs Python client is currently in Beta. We welcome feedback and feature requests either in this repository's issue tracker or on our feedback issue
Installation
Install the client using pip:
pip install gitlab-mlops
Alternatively, to install the latest version from the source, use Poetry:
# Clone the repository
git clone https://gitlab.com/gitlab-org/modelops/mlops/gitlab-mlops.git
cd gitlab-mlops
# Install dependencies
poetry install
Usage
Configuration
Configure the client using environment variables or initialization arguments.
Using Environment Variables:
export MLFLOW_TRACKING_URI="https://gitlab.com/api/v4/projects/<project_id>/mlflow"
export MLFLOW_TRACKING_TOKEN="your_access_token"
from gitlab_mlops import Client
client = Client()
Using Initialization Arguments:
from gitlab_mlops import Client
client = Client(
tracking_uri="https://gitlab.com/api/v4/projects/<project_id>/mlflow",
gitlab_token="your_access_token"
)
Create a New Experiment
from gitlab_mlops import Client
client = Client()
experiment = client.create_experiment("Experiment Name")
Create a New Run
from gitlab_mlops import Client
client = Client()
experiment = client.get_experiment(name="Experiment Name")
run = experiment.create_run()
Log Parameters, Metrics, and Model artifacts
from gitlab_mlops import Client
client = Client()
run = client.get_run(run_id="19e547d3-8de7-42c3-9575-fae1142dec69")
run.log_param(key="param_name", value="value")
run.log_metric(key="metric_name", value=0.95)
run.log_artifact(
local_path="<path to the model file or directory>",
artifact_path="<optional relative path to log the artifact(s) at>"
)
Create a New Model
from gitlab_mlops import Client
client = Client()
model = client.create_model(name="Model Name", description="Model Description")
Create a New Model Version
from gitlab_mlops import Client
client = Client()
model = client.get_model(name="Model Name")
model_version = model.create_version(description="New version", version="1.0.0")
model_version.log_param(key="param_name", value="value")
model_version.log_text("How to run this model [...]", "README.md")
Importing existing models
To import existing models from various external sources, you can use the export_to_gitlab method.
This method allows you to import models from the following sources:
- Google Cloud Platform - Vertex AI
Importing from Google Cloud Platform - Vertex AI
from gitlab_mlops import Client
from gitlab_mlops.providers.gcp.vertex import VertexAIClient
client = Client()
vertex = VertexAIClient(
project_id="your_project_id",
location="us-central1",
client=client
)
resource_name = "projects/your_project_id/locations/us-central1/models/your_model_id"
vertex.export_model_to_gitlab(
model_id=resource_name
)
Metadata
Release files for gitlab-mlops 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| gitlab_mlops-0.3.0.tar.gz | 12.6 kB | Without provenance | Details for gitlab_mlops-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| gitlab_mlops-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for gitlab_mlops-0.3.0-py3-none-any.whl |
Total release size: 29.9 kB
Release files / gitlab_mlops-0.3.0.tar.gz
| Download URL | gitlab_mlops-0.3.0.tar.gz |
|---|---|
| Size | 12.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7c5497a8fddcf8dd06f854cfb7db2a84c372cb14c1ba9e54b34cbe41b23bca77
|
|
BLAKE2b-256 checksum How to use checksums |
57473bc089963652c73fe96ce9d10414ebb0ed29d70e4f1c82ad2cb3f71cea0a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
poetry/2.1.1 CPython/3.11.9 Linux/5.15.154+
|
Release files / gitlab_mlops-0.3.0-py3-none-any.whl
| Download URL | gitlab_mlops-0.3.0-py3-none-any.whl |
|---|---|
| Size | 17.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
601cce15ed28d4cf4b2c4ded524ce67b31ba17fcd97e951624e2c7110ca148ea
|
|
BLAKE2b-256 checksum How to use checksums |
0f7ac21cea0478f7ea0b641cfdf5feb8919374c1c6368d2ca196bd18087c7f46
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
poetry/2.1.1 CPython/3.11.9 Linux/5.15.154+
|
Security for gitlab-mlops 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.