mlflow-triton-control 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mlflow_triton_control-0.2.0/LICENSE +201 -0
- mlflow_triton_control-0.2.0/PKG-INFO +98 -0
- mlflow_triton_control-0.2.0/README.md +86 -0
- mlflow_triton_control-0.2.0/mlflow_triton_control/__init__.py +5 -0
- mlflow_triton_control-0.2.0/mlflow_triton_control/deployment_client.py +126 -0
- mlflow_triton_control-0.2.0/mlflow_triton_control/triton.py +92 -0
- mlflow_triton_control-0.2.0/mlflow_triton_control.egg-info/PKG-INFO +98 -0
- mlflow_triton_control-0.2.0/mlflow_triton_control.egg-info/SOURCES.txt +14 -0
- mlflow_triton_control-0.2.0/mlflow_triton_control.egg-info/dependency_links.txt +1 -0
- mlflow_triton_control-0.2.0/mlflow_triton_control.egg-info/entry_points.txt +2 -0
- mlflow_triton_control-0.2.0/mlflow_triton_control.egg-info/requires.txt +2 -0
- mlflow_triton_control-0.2.0/mlflow_triton_control.egg-info/top_level.txt +1 -0
- mlflow_triton_control-0.2.0/pyproject.toml +19 -0
- mlflow_triton_control-0.2.0/setup.cfg +4 -0
- mlflow_triton_control-0.2.0/tests/test_deployment_client.py +71 -0
- mlflow_triton_control-0.2.0/tests/test_triton_flavor.py +111 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mlflow-triton-control
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: MLflow deployment target for Triton Control
|
|
5
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
6
|
+
Requires-Python: >=3.10
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Requires-Dist: mlflow<4,>=3
|
|
10
|
+
Requires-Dist: httpx<1,>=0.27
|
|
11
|
+
Dynamic: license-file
|
|
12
|
+
|
|
13
|
+
# mlflow-triton-control
|
|
14
|
+
|
|
15
|
+
MLflow deployment target for models that already exist in a Triton S3 model
|
|
16
|
+
repository. Install this Python package in the environment running the MLflow
|
|
17
|
+
CLI or Python API. Triton Control creates the Kubernetes deployment and resolves
|
|
18
|
+
the selected user-owned S3 profile.
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
python -m build
|
|
22
|
+
python -m pip install dist/mlflow_triton_control-*.whl
|
|
23
|
+
mlflow deployments help -t triton-control
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## How MLflow finds the plugin
|
|
27
|
+
|
|
28
|
+
`mlflow deployments create` is a command provided by MLflow. This package
|
|
29
|
+
registers the deployment target through its Python package metadata:
|
|
30
|
+
|
|
31
|
+
```toml
|
|
32
|
+
[project.entry-points."mlflow.deployments"]
|
|
33
|
+
triton-control = "mlflow_triton_control.deployment_client"
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
For `--target triton-control://triton-control:8000`, MLflow looks up the
|
|
37
|
+
`triton-control` entry point among installed packages, loads this module, and
|
|
38
|
+
calls `TritonControlDeploymentClient.create_deployment()`. That class inherits
|
|
39
|
+
from MLflow's `BaseDeploymentClient` and sends the deployment request to the
|
|
40
|
+
Triton Control API. MLflow reads entry-point metadata; it does not search
|
|
41
|
+
through every package's source files. The package must be installed in the
|
|
42
|
+
same Python environment as the `mlflow` CLI.
|
|
43
|
+
|
|
44
|
+
## Log a Triton model in MLflow
|
|
45
|
+
|
|
46
|
+
Like NVIDIA's Triton MLflow plugin, this package provides a `triton` model
|
|
47
|
+
flavor for a complete Triton model directory. The directory must contain at
|
|
48
|
+
least one numbered version; `config.pbtxt` may be included at
|
|
49
|
+
its root. The MLflow Model contains an `MLmodel` file with a `triton` flavor
|
|
50
|
+
entry and a copy of the entire directory under `model/`.
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
from mlflow_triton_control import triton
|
|
54
|
+
|
|
55
|
+
model_info = triton.log_model(
|
|
56
|
+
triton_model_path="/tmp/model-repository/iris_classifier",
|
|
57
|
+
name="triton-model",
|
|
58
|
+
registered_model_name="iris-serving",
|
|
59
|
+
)
|
|
60
|
+
print(model_info.registered_model_version)
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
`triton.load_model("models:/iris-serving/1")` downloads the registered model
|
|
64
|
+
and returns the local Triton model directory. Omit `registered_model_name` to
|
|
65
|
+
save a model without creating a Registry version. This API is in the plugin
|
|
66
|
+
package, not in MLflow's `mlflow.triton` namespace.
|
|
67
|
+
|
|
68
|
+
The current deployment client still accepts an already-published `s3://` Triton
|
|
69
|
+
repository URI. Deploying directly from `models:/...` and copying that version
|
|
70
|
+
to the selected S3 profile are separate planned changes. The current Iris
|
|
71
|
+
workflow therefore continues to use the S3 URI.
|
|
72
|
+
|
|
73
|
+
## Argo Workflows
|
|
74
|
+
|
|
75
|
+
Submit the workflow through Triton Control's authenticated Argo proxy. Mark the
|
|
76
|
+
deployment template with these Workflow annotations:
|
|
77
|
+
|
|
78
|
+
```yaml
|
|
79
|
+
metadata:
|
|
80
|
+
name: train-iris
|
|
81
|
+
annotations:
|
|
82
|
+
triton-control.ai/mlflow-deploy-template: deploy
|
|
83
|
+
triton-control.ai/mlflow-deployment-name: iris-classifier
|
|
84
|
+
triton-control.ai/mlflow-s3-profile-name: workflow-training
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
The backend resolves the profile name and its linked Argo artifact repository
|
|
88
|
+
for the submitting user. It sets `spec.artifactRepositoryRef` and injects
|
|
89
|
+
`TRITON_CONTROL_TOKEN`, `TRITON_CONTROL_S3_PROFILE_ID`, and
|
|
90
|
+
`TRITON_CONTROL_S3_BUCKET` into the named `script` or `container` template.
|
|
91
|
+
Use the injected ID with `-C s3_profile_id="$TRITON_CONTROL_S3_PROFILE_ID"`.
|
|
92
|
+
The token is valid for 60 minutes and limited
|
|
93
|
+
to the specified deployment and S3 profile. The Workflow receives a five-minute
|
|
94
|
+
completion TTL unless it already defines one, and the Secret receives a
|
|
95
|
+
Workflow owner reference for garbage collection.
|
|
96
|
+
|
|
97
|
+
The opted-in Workflow must have a fixed `metadata.name` and run in the Triton
|
|
98
|
+
Control namespace. Direct submissions to Argo bypass this token injection.
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# mlflow-triton-control
|
|
2
|
+
|
|
3
|
+
MLflow deployment target for models that already exist in a Triton S3 model
|
|
4
|
+
repository. Install this Python package in the environment running the MLflow
|
|
5
|
+
CLI or Python API. Triton Control creates the Kubernetes deployment and resolves
|
|
6
|
+
the selected user-owned S3 profile.
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
python -m build
|
|
10
|
+
python -m pip install dist/mlflow_triton_control-*.whl
|
|
11
|
+
mlflow deployments help -t triton-control
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## How MLflow finds the plugin
|
|
15
|
+
|
|
16
|
+
`mlflow deployments create` is a command provided by MLflow. This package
|
|
17
|
+
registers the deployment target through its Python package metadata:
|
|
18
|
+
|
|
19
|
+
```toml
|
|
20
|
+
[project.entry-points."mlflow.deployments"]
|
|
21
|
+
triton-control = "mlflow_triton_control.deployment_client"
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
For `--target triton-control://triton-control:8000`, MLflow looks up the
|
|
25
|
+
`triton-control` entry point among installed packages, loads this module, and
|
|
26
|
+
calls `TritonControlDeploymentClient.create_deployment()`. That class inherits
|
|
27
|
+
from MLflow's `BaseDeploymentClient` and sends the deployment request to the
|
|
28
|
+
Triton Control API. MLflow reads entry-point metadata; it does not search
|
|
29
|
+
through every package's source files. The package must be installed in the
|
|
30
|
+
same Python environment as the `mlflow` CLI.
|
|
31
|
+
|
|
32
|
+
## Log a Triton model in MLflow
|
|
33
|
+
|
|
34
|
+
Like NVIDIA's Triton MLflow plugin, this package provides a `triton` model
|
|
35
|
+
flavor for a complete Triton model directory. The directory must contain at
|
|
36
|
+
least one numbered version; `config.pbtxt` may be included at
|
|
37
|
+
its root. The MLflow Model contains an `MLmodel` file with a `triton` flavor
|
|
38
|
+
entry and a copy of the entire directory under `model/`.
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
from mlflow_triton_control import triton
|
|
42
|
+
|
|
43
|
+
model_info = triton.log_model(
|
|
44
|
+
triton_model_path="/tmp/model-repository/iris_classifier",
|
|
45
|
+
name="triton-model",
|
|
46
|
+
registered_model_name="iris-serving",
|
|
47
|
+
)
|
|
48
|
+
print(model_info.registered_model_version)
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
`triton.load_model("models:/iris-serving/1")` downloads the registered model
|
|
52
|
+
and returns the local Triton model directory. Omit `registered_model_name` to
|
|
53
|
+
save a model without creating a Registry version. This API is in the plugin
|
|
54
|
+
package, not in MLflow's `mlflow.triton` namespace.
|
|
55
|
+
|
|
56
|
+
The current deployment client still accepts an already-published `s3://` Triton
|
|
57
|
+
repository URI. Deploying directly from `models:/...` and copying that version
|
|
58
|
+
to the selected S3 profile are separate planned changes. The current Iris
|
|
59
|
+
workflow therefore continues to use the S3 URI.
|
|
60
|
+
|
|
61
|
+
## Argo Workflows
|
|
62
|
+
|
|
63
|
+
Submit the workflow through Triton Control's authenticated Argo proxy. Mark the
|
|
64
|
+
deployment template with these Workflow annotations:
|
|
65
|
+
|
|
66
|
+
```yaml
|
|
67
|
+
metadata:
|
|
68
|
+
name: train-iris
|
|
69
|
+
annotations:
|
|
70
|
+
triton-control.ai/mlflow-deploy-template: deploy
|
|
71
|
+
triton-control.ai/mlflow-deployment-name: iris-classifier
|
|
72
|
+
triton-control.ai/mlflow-s3-profile-name: workflow-training
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
The backend resolves the profile name and its linked Argo artifact repository
|
|
76
|
+
for the submitting user. It sets `spec.artifactRepositoryRef` and injects
|
|
77
|
+
`TRITON_CONTROL_TOKEN`, `TRITON_CONTROL_S3_PROFILE_ID`, and
|
|
78
|
+
`TRITON_CONTROL_S3_BUCKET` into the named `script` or `container` template.
|
|
79
|
+
Use the injected ID with `-C s3_profile_id="$TRITON_CONTROL_S3_PROFILE_ID"`.
|
|
80
|
+
The token is valid for 60 minutes and limited
|
|
81
|
+
to the specified deployment and S3 profile. The Workflow receives a five-minute
|
|
82
|
+
completion TTL unless it already defines one, and the Secret receives a
|
|
83
|
+
Workflow owner reference for garbage collection.
|
|
84
|
+
|
|
85
|
+
The opted-in Workflow must have a fixed `metadata.name` and run in the Triton
|
|
86
|
+
Control namespace. Direct submissions to Argo bypass this token injection.
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"""MLflow deployment client backed by Triton Control's deployment API."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
import re
|
|
7
|
+
import time
|
|
8
|
+
from urllib.parse import quote, urlsplit
|
|
9
|
+
|
|
10
|
+
import httpx
|
|
11
|
+
from mlflow.deployments import BaseDeploymentClient
|
|
12
|
+
from mlflow.exceptions import MlflowException
|
|
13
|
+
|
|
14
|
+
_NAME = re.compile(r"[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\Z")
|
|
15
|
+
_MODEL = re.compile(r"[A-Za-z0-9][A-Za-z0-9_.-]*\Z")
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def target_help() -> str:
|
|
19
|
+
return (
|
|
20
|
+
"Target: triton-control://<triton-control-host>[:port]. "
|
|
21
|
+
"Install this package in the MLflow CLI environment. "
|
|
22
|
+
"Use -m s3://<profile-bucket>/<repository-prefix>/<model-name> and "
|
|
23
|
+
"-C s3_profile_id=<owned-profile-id> -C image=<triton-image>. "
|
|
24
|
+
"The model must already exist in Triton repository format. "
|
|
25
|
+
"Set TRITON_CONTROL_TOKEN to a user-bound API token. "
|
|
26
|
+
"MLflow models:/ and runs:/ artifacts, update, predict and local serving are unsupported."
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def run_local(target, name, model_uri, flavor=None, config=None):
|
|
31
|
+
raise MlflowException("Local Triton serving is not supported by triton-control")
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class TritonControlDeploymentClient(BaseDeploymentClient):
|
|
35
|
+
"""Create and manage user-owned Triton Control deployments."""
|
|
36
|
+
|
|
37
|
+
def __init__(self, target_uri):
|
|
38
|
+
super().__init__(target_uri)
|
|
39
|
+
parsed = urlsplit(target_uri)
|
|
40
|
+
if parsed.scheme != "triton-control" or not parsed.netloc or parsed.path not in {"", "/"}:
|
|
41
|
+
raise MlflowException("Target URI must be triton-control://<host>[:port]")
|
|
42
|
+
self._base_url = f"http://{parsed.netloc}"
|
|
43
|
+
|
|
44
|
+
def _request(self, method, path, **kwargs):
|
|
45
|
+
token = os.getenv("TRITON_CONTROL_TOKEN", "").strip()
|
|
46
|
+
if not token:
|
|
47
|
+
raise MlflowException("TRITON_CONTROL_TOKEN is required")
|
|
48
|
+
try:
|
|
49
|
+
with httpx.Client(base_url=self._base_url, timeout=10.0, follow_redirects=False) as client:
|
|
50
|
+
response = client.request(method, path, headers={"Authorization": f"Bearer {token}"}, **kwargs)
|
|
51
|
+
response.raise_for_status()
|
|
52
|
+
return response.json()
|
|
53
|
+
except httpx.HTTPStatusError as exc:
|
|
54
|
+
try:
|
|
55
|
+
detail = exc.response.json().get("detail", "Request failed")
|
|
56
|
+
except (ValueError, AttributeError):
|
|
57
|
+
detail = "Request failed"
|
|
58
|
+
raise MlflowException(f"Triton Control returned HTTP {exc.response.status_code}: {detail}") from exc
|
|
59
|
+
except httpx.RequestError as exc:
|
|
60
|
+
raise MlflowException(f"Triton Control is unavailable: {type(exc).__name__}") from exc
|
|
61
|
+
|
|
62
|
+
def create_deployment(self, name, model_uri, flavor=None, config=None, endpoint=None):
|
|
63
|
+
if endpoint is not None:
|
|
64
|
+
raise MlflowException("endpoint is not supported")
|
|
65
|
+
if flavor not in {None, "triton"}:
|
|
66
|
+
raise MlflowException("Only the triton flavor is supported")
|
|
67
|
+
if not _NAME.fullmatch(name):
|
|
68
|
+
raise MlflowException("name must be a lowercase Kubernetes deployment name")
|
|
69
|
+
config = config or {}
|
|
70
|
+
try:
|
|
71
|
+
profile_id = int(config["s3_profile_id"])
|
|
72
|
+
image = str(config["image"]).strip()
|
|
73
|
+
except (KeyError, TypeError, ValueError) as exc:
|
|
74
|
+
raise MlflowException("s3_profile_id and image are required") from exc
|
|
75
|
+
if profile_id <= 0 or not image:
|
|
76
|
+
raise MlflowException("s3_profile_id must be positive and image must not be empty")
|
|
77
|
+
try:
|
|
78
|
+
timeout = float(config.get("wait_timeout_seconds", 300))
|
|
79
|
+
except (TypeError, ValueError) as exc:
|
|
80
|
+
raise MlflowException("wait_timeout_seconds must be a positive number") from exc
|
|
81
|
+
if timeout <= 0:
|
|
82
|
+
raise MlflowException("wait_timeout_seconds must be a positive number")
|
|
83
|
+
uri = urlsplit(model_uri)
|
|
84
|
+
parts = uri.path.strip("/").split("/")
|
|
85
|
+
if (uri.scheme != "s3" or not uri.netloc or uri.query or uri.fragment
|
|
86
|
+
or len(parts) < 2 or any(part in {"", ".", ".."} for part in parts)
|
|
87
|
+
or not _MODEL.fullmatch(parts[-1])):
|
|
88
|
+
raise MlflowException("model_uri must be s3://<bucket>/<repository-prefix>/<model-name>")
|
|
89
|
+
prefix, model_name = "/".join(parts[:-1]), parts[-1]
|
|
90
|
+
payload = {
|
|
91
|
+
"deployment_name": name,
|
|
92
|
+
"s3_profile_id": profile_id,
|
|
93
|
+
"model_uri": model_uri,
|
|
94
|
+
"repository_prefix": prefix,
|
|
95
|
+
"model_name": model_name,
|
|
96
|
+
"image": image,
|
|
97
|
+
"model_control_mode": "explicit",
|
|
98
|
+
}
|
|
99
|
+
result = self._request("POST", "/api/deployments", json=payload)
|
|
100
|
+
deadline = time.monotonic() + timeout
|
|
101
|
+
while True:
|
|
102
|
+
current = self.get_deployment(name)
|
|
103
|
+
if current["status"] == "ready":
|
|
104
|
+
return current
|
|
105
|
+
if time.monotonic() >= deadline:
|
|
106
|
+
raise MlflowException(
|
|
107
|
+
f"Deployment {name} (instance {result.get('instance_id')}) did not become ready: "
|
|
108
|
+
f"{current.get('status_detail', current['status'])}"
|
|
109
|
+
)
|
|
110
|
+
time.sleep(min(3.0, max(0.0, deadline - time.monotonic())))
|
|
111
|
+
|
|
112
|
+
def get_deployment(self, name):
|
|
113
|
+
deployment = self._request("GET", f"/api/deployments/mlflow/{quote(name, safe='')}")
|
|
114
|
+
return {**deployment, "flavor": "triton"}
|
|
115
|
+
|
|
116
|
+
def list_deployments(self):
|
|
117
|
+
return self._request("GET", "/api/deployments/mlflow")
|
|
118
|
+
|
|
119
|
+
def delete_deployment(self, name):
|
|
120
|
+
return self._request("DELETE", f"/api/deployments/mlflow/{quote(name, safe='')}")
|
|
121
|
+
|
|
122
|
+
def update_deployment(self, name, model_uri=None, flavor=None, config=None, endpoint=None):
|
|
123
|
+
raise MlflowException("Updating deployments is not supported")
|
|
124
|
+
|
|
125
|
+
def predict(self, deployment_name=None, inputs=None, endpoint=None):
|
|
126
|
+
raise MlflowException("Prediction is not supported")
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"""MLflow flavor for a complete Triton model repository directory."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import shutil
|
|
6
|
+
import sys
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
from mlflow.artifacts import download_artifacts
|
|
10
|
+
from mlflow.exceptions import MlflowException
|
|
11
|
+
from mlflow.models import Model
|
|
12
|
+
|
|
13
|
+
FLAVOR_NAME = "triton"
|
|
14
|
+
_MODEL_DATA = "model"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def _validate_repository(model_path: Path) -> None:
|
|
18
|
+
if not model_path.is_dir():
|
|
19
|
+
raise MlflowException(f"Triton model directory does not exist: {model_path}")
|
|
20
|
+
if model_path.is_symlink() or any(path.is_symlink() for path in model_path.rglob("*")):
|
|
21
|
+
raise MlflowException("Triton model directory must not contain symbolic links")
|
|
22
|
+
versions = [
|
|
23
|
+
path for path in model_path.iterdir()
|
|
24
|
+
if path.is_dir() and path.name.isascii() and path.name.isdecimal()
|
|
25
|
+
and int(path.name) > 0
|
|
26
|
+
]
|
|
27
|
+
if not versions:
|
|
28
|
+
raise MlflowException(
|
|
29
|
+
"Triton model directory must contain a numbered version"
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def save_model(triton_model_path, path, mlflow_model=None):
|
|
34
|
+
"""Save one Triton model directory as an MLflow Model with the triton flavor.
|
|
35
|
+
|
|
36
|
+
``triton_model_path`` points at the model-name directory containing
|
|
37
|
+
``config.pbtxt`` (if needed) and numbered version directories.
|
|
38
|
+
"""
|
|
39
|
+
source = Path(triton_model_path).expanduser()
|
|
40
|
+
_validate_repository(source)
|
|
41
|
+
source = source.resolve()
|
|
42
|
+
destination = Path(path).expanduser().resolve()
|
|
43
|
+
if destination.exists():
|
|
44
|
+
raise MlflowException(f"MLflow model path already exists: {destination}")
|
|
45
|
+
if destination == source or destination.is_relative_to(source):
|
|
46
|
+
raise MlflowException("MLflow model path must be outside the Triton model directory")
|
|
47
|
+
|
|
48
|
+
destination.mkdir(parents=True)
|
|
49
|
+
shutil.copytree(source, destination / _MODEL_DATA)
|
|
50
|
+
model = mlflow_model or Model()
|
|
51
|
+
model.add_flavor(FLAVOR_NAME, data=_MODEL_DATA, model_name=source.name)
|
|
52
|
+
model.save(str(destination / "MLmodel"))
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def log_model(
|
|
56
|
+
triton_model_path,
|
|
57
|
+
name="triton-model",
|
|
58
|
+
registered_model_name=None,
|
|
59
|
+
await_registration_for=300,
|
|
60
|
+
run_id=None,
|
|
61
|
+
metadata=None,
|
|
62
|
+
):
|
|
63
|
+
"""Log a Triton repository and optionally register a model version.
|
|
64
|
+
|
|
65
|
+
Returns MLflow's ``ModelInfo``. A registry version is created only when
|
|
66
|
+
``registered_model_name`` is given.
|
|
67
|
+
"""
|
|
68
|
+
return Model.log(
|
|
69
|
+
artifact_path=None,
|
|
70
|
+
flavor=sys.modules[__name__],
|
|
71
|
+
name=name,
|
|
72
|
+
registered_model_name=registered_model_name,
|
|
73
|
+
await_registration_for=await_registration_for,
|
|
74
|
+
run_id=run_id,
|
|
75
|
+
metadata=metadata,
|
|
76
|
+
flavor_name=FLAVOR_NAME,
|
|
77
|
+
triton_model_path=triton_model_path,
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def load_model(model_uri):
|
|
82
|
+
"""Download an MLflow Triton model and return its repository directory."""
|
|
83
|
+
model_root = Path(download_artifacts(artifact_uri=model_uri)).resolve()
|
|
84
|
+
model = Model.load(str(model_root / "MLmodel"))
|
|
85
|
+
flavor = model.flavors.get(FLAVOR_NAME)
|
|
86
|
+
if not flavor:
|
|
87
|
+
raise MlflowException(f"Model has no {FLAVOR_NAME} flavor: {model_uri}")
|
|
88
|
+
data_path = (model_root / flavor.get("data", "")).resolve()
|
|
89
|
+
if not data_path.is_relative_to(model_root) or data_path == model_root:
|
|
90
|
+
raise MlflowException("Triton flavor contains an invalid data path")
|
|
91
|
+
_validate_repository(data_path)
|
|
92
|
+
return data_path
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mlflow-triton-control
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: MLflow deployment target for Triton Control
|
|
5
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
6
|
+
Requires-Python: >=3.10
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Requires-Dist: mlflow<4,>=3
|
|
10
|
+
Requires-Dist: httpx<1,>=0.27
|
|
11
|
+
Dynamic: license-file
|
|
12
|
+
|
|
13
|
+
# mlflow-triton-control
|
|
14
|
+
|
|
15
|
+
MLflow deployment target for models that already exist in a Triton S3 model
|
|
16
|
+
repository. Install this Python package in the environment running the MLflow
|
|
17
|
+
CLI or Python API. Triton Control creates the Kubernetes deployment and resolves
|
|
18
|
+
the selected user-owned S3 profile.
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
python -m build
|
|
22
|
+
python -m pip install dist/mlflow_triton_control-*.whl
|
|
23
|
+
mlflow deployments help -t triton-control
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## How MLflow finds the plugin
|
|
27
|
+
|
|
28
|
+
`mlflow deployments create` is a command provided by MLflow. This package
|
|
29
|
+
registers the deployment target through its Python package metadata:
|
|
30
|
+
|
|
31
|
+
```toml
|
|
32
|
+
[project.entry-points."mlflow.deployments"]
|
|
33
|
+
triton-control = "mlflow_triton_control.deployment_client"
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
For `--target triton-control://triton-control:8000`, MLflow looks up the
|
|
37
|
+
`triton-control` entry point among installed packages, loads this module, and
|
|
38
|
+
calls `TritonControlDeploymentClient.create_deployment()`. That class inherits
|
|
39
|
+
from MLflow's `BaseDeploymentClient` and sends the deployment request to the
|
|
40
|
+
Triton Control API. MLflow reads entry-point metadata; it does not search
|
|
41
|
+
through every package's source files. The package must be installed in the
|
|
42
|
+
same Python environment as the `mlflow` CLI.
|
|
43
|
+
|
|
44
|
+
## Log a Triton model in MLflow
|
|
45
|
+
|
|
46
|
+
Like NVIDIA's Triton MLflow plugin, this package provides a `triton` model
|
|
47
|
+
flavor for a complete Triton model directory. The directory must contain at
|
|
48
|
+
least one numbered version; `config.pbtxt` may be included at
|
|
49
|
+
its root. The MLflow Model contains an `MLmodel` file with a `triton` flavor
|
|
50
|
+
entry and a copy of the entire directory under `model/`.
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
from mlflow_triton_control import triton
|
|
54
|
+
|
|
55
|
+
model_info = triton.log_model(
|
|
56
|
+
triton_model_path="/tmp/model-repository/iris_classifier",
|
|
57
|
+
name="triton-model",
|
|
58
|
+
registered_model_name="iris-serving",
|
|
59
|
+
)
|
|
60
|
+
print(model_info.registered_model_version)
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
`triton.load_model("models:/iris-serving/1")` downloads the registered model
|
|
64
|
+
and returns the local Triton model directory. Omit `registered_model_name` to
|
|
65
|
+
save a model without creating a Registry version. This API is in the plugin
|
|
66
|
+
package, not in MLflow's `mlflow.triton` namespace.
|
|
67
|
+
|
|
68
|
+
The current deployment client still accepts an already-published `s3://` Triton
|
|
69
|
+
repository URI. Deploying directly from `models:/...` and copying that version
|
|
70
|
+
to the selected S3 profile are separate planned changes. The current Iris
|
|
71
|
+
workflow therefore continues to use the S3 URI.
|
|
72
|
+
|
|
73
|
+
## Argo Workflows
|
|
74
|
+
|
|
75
|
+
Submit the workflow through Triton Control's authenticated Argo proxy. Mark the
|
|
76
|
+
deployment template with these Workflow annotations:
|
|
77
|
+
|
|
78
|
+
```yaml
|
|
79
|
+
metadata:
|
|
80
|
+
name: train-iris
|
|
81
|
+
annotations:
|
|
82
|
+
triton-control.ai/mlflow-deploy-template: deploy
|
|
83
|
+
triton-control.ai/mlflow-deployment-name: iris-classifier
|
|
84
|
+
triton-control.ai/mlflow-s3-profile-name: workflow-training
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
The backend resolves the profile name and its linked Argo artifact repository
|
|
88
|
+
for the submitting user. It sets `spec.artifactRepositoryRef` and injects
|
|
89
|
+
`TRITON_CONTROL_TOKEN`, `TRITON_CONTROL_S3_PROFILE_ID`, and
|
|
90
|
+
`TRITON_CONTROL_S3_BUCKET` into the named `script` or `container` template.
|
|
91
|
+
Use the injected ID with `-C s3_profile_id="$TRITON_CONTROL_S3_PROFILE_ID"`.
|
|
92
|
+
The token is valid for 60 minutes and limited
|
|
93
|
+
to the specified deployment and S3 profile. The Workflow receives a five-minute
|
|
94
|
+
completion TTL unless it already defines one, and the Secret receives a
|
|
95
|
+
Workflow owner reference for garbage collection.
|
|
96
|
+
|
|
97
|
+
The opted-in Workflow must have a fixed `metadata.name` and run in the Triton
|
|
98
|
+
Control namespace. Direct submissions to Argo bypass this token injection.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
mlflow_triton_control/__init__.py
|
|
5
|
+
mlflow_triton_control/deployment_client.py
|
|
6
|
+
mlflow_triton_control/triton.py
|
|
7
|
+
mlflow_triton_control.egg-info/PKG-INFO
|
|
8
|
+
mlflow_triton_control.egg-info/SOURCES.txt
|
|
9
|
+
mlflow_triton_control.egg-info/dependency_links.txt
|
|
10
|
+
mlflow_triton_control.egg-info/entry_points.txt
|
|
11
|
+
mlflow_triton_control.egg-info/requires.txt
|
|
12
|
+
mlflow_triton_control.egg-info/top_level.txt
|
|
13
|
+
tests/test_deployment_client.py
|
|
14
|
+
tests/test_triton_flavor.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
mlflow_triton_control
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "mlflow-triton-control"
|
|
7
|
+
version = "0.2.0"
|
|
8
|
+
description = "MLflow deployment target for Triton Control"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
classifiers = ["License :: OSI Approved :: Apache Software License"]
|
|
13
|
+
dependencies = ["mlflow>=3,<4", "httpx>=0.27,<1"]
|
|
14
|
+
|
|
15
|
+
[project.entry-points."mlflow.deployments"]
|
|
16
|
+
triton-control = "mlflow_triton_control.deployment_client"
|
|
17
|
+
|
|
18
|
+
[tool.setuptools.packages.find]
|
|
19
|
+
include = ["mlflow_triton_control*"]
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"""Contract checks for the package without requiring an MLflow server."""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import sys
|
|
5
|
+
import types
|
|
6
|
+
import unittest
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from unittest.mock import Mock, patch
|
|
9
|
+
|
|
10
|
+
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
|
11
|
+
|
|
12
|
+
mlflow = types.ModuleType("mlflow")
|
|
13
|
+
deployments = types.ModuleType("mlflow.deployments")
|
|
14
|
+
exceptions = types.ModuleType("mlflow.exceptions")
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class BaseDeploymentClient:
|
|
18
|
+
def __init__(self, target_uri):
|
|
19
|
+
self.target_uri = target_uri
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class MlflowException(Exception):
|
|
23
|
+
pass
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
deployments.BaseDeploymentClient = BaseDeploymentClient
|
|
27
|
+
exceptions.MlflowException = MlflowException
|
|
28
|
+
with patch.dict(sys.modules, {"mlflow": mlflow, "mlflow.deployments": deployments, "mlflow.exceptions": exceptions}):
|
|
29
|
+
from mlflow_triton_control.deployment_client import TritonControlDeploymentClient
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class DeploymentClientTests(unittest.TestCase):
|
|
33
|
+
def setUp(self) -> None:
|
|
34
|
+
self.client = TritonControlDeploymentClient("triton-control://control.test")
|
|
35
|
+
|
|
36
|
+
def test_create_derives_repository_from_model_uri_and_waits_for_model(self) -> None:
|
|
37
|
+
with (
|
|
38
|
+
patch.object(self.client, "_request") as request,
|
|
39
|
+
patch.dict(os.environ, {"TRITON_CONTROL_TOKEN": "token"}),
|
|
40
|
+
):
|
|
41
|
+
request.side_effect = [
|
|
42
|
+
{"instance_id": 42},
|
|
43
|
+
{"name": "iris", "status": "starting"},
|
|
44
|
+
{"name": "iris", "status": "ready"},
|
|
45
|
+
]
|
|
46
|
+
with patch("time.sleep"):
|
|
47
|
+
result = self.client.create_deployment(
|
|
48
|
+
"iris", "s3://models/dev/iris_classifier",
|
|
49
|
+
config={"s3_profile_id": 7, "image": "triton:latest"},
|
|
50
|
+
)
|
|
51
|
+
self.assertEqual(result["status"], "ready")
|
|
52
|
+
self.assertEqual(result["flavor"], "triton")
|
|
53
|
+
payload = request.call_args_list[0].kwargs["json"]
|
|
54
|
+
self.assertEqual(payload["repository_prefix"], "dev")
|
|
55
|
+
self.assertEqual(payload["model_name"], "iris_classifier")
|
|
56
|
+
|
|
57
|
+
def test_mlflow_registry_uri_is_rejected(self) -> None:
|
|
58
|
+
with self.assertRaises(MlflowException):
|
|
59
|
+
self.client.create_deployment(
|
|
60
|
+
"iris", "models:/iris/1", config={"s3_profile_id": 7, "image": "triton:latest"}
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
def test_invalid_timeout_is_rejected_before_create(self) -> None:
|
|
64
|
+
self.client._request = Mock()
|
|
65
|
+
with self.assertRaisesRegex(MlflowException, "wait_timeout_seconds must be a positive number"):
|
|
66
|
+
self.client.create_deployment(
|
|
67
|
+
"iris",
|
|
68
|
+
"s3://models/repository/iris",
|
|
69
|
+
config={"s3_profile_id": 7, "image": "triton:latest", "wait_timeout_seconds": "later"},
|
|
70
|
+
)
|
|
71
|
+
self.client._request.assert_not_called()
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"""Checks for packaging and retrieving a complete Triton repository."""
|
|
2
|
+
|
|
3
|
+
import importlib
|
|
4
|
+
import json
|
|
5
|
+
import sys
|
|
6
|
+
import tempfile
|
|
7
|
+
import types
|
|
8
|
+
import unittest
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
from unittest.mock import Mock, patch
|
|
11
|
+
|
|
12
|
+
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class MlflowException(Exception):
|
|
16
|
+
pass
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class Model:
|
|
20
|
+
log = Mock()
|
|
21
|
+
|
|
22
|
+
def __init__(self):
|
|
23
|
+
self.flavors = {}
|
|
24
|
+
|
|
25
|
+
def add_flavor(self, name, **params):
|
|
26
|
+
self.flavors[name] = params
|
|
27
|
+
return self
|
|
28
|
+
|
|
29
|
+
def save(self, path):
|
|
30
|
+
Path(path).write_text(json.dumps({"flavors": self.flavors}))
|
|
31
|
+
|
|
32
|
+
@classmethod
|
|
33
|
+
def load(cls, path):
|
|
34
|
+
result = cls()
|
|
35
|
+
result.flavors = json.loads(Path(path).read_text())["flavors"]
|
|
36
|
+
return result
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
mlflow = types.ModuleType("mlflow")
|
|
40
|
+
artifacts = types.ModuleType("mlflow.artifacts")
|
|
41
|
+
exceptions = types.ModuleType("mlflow.exceptions")
|
|
42
|
+
models = types.ModuleType("mlflow.models")
|
|
43
|
+
deployments = types.ModuleType("mlflow.deployments")
|
|
44
|
+
artifacts.download_artifacts = Mock()
|
|
45
|
+
exceptions.MlflowException = MlflowException
|
|
46
|
+
models.Model = Model
|
|
47
|
+
deployments.BaseDeploymentClient = type("BaseDeploymentClient", (), {})
|
|
48
|
+
with patch.dict(sys.modules, {
|
|
49
|
+
"mlflow": mlflow, "mlflow.artifacts": artifacts,
|
|
50
|
+
"mlflow.exceptions": exceptions, "mlflow.models": models,
|
|
51
|
+
"mlflow.deployments": deployments,
|
|
52
|
+
}):
|
|
53
|
+
triton = importlib.import_module("mlflow_triton_control.triton")
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class TritonFlavorTests(unittest.TestCase):
|
|
57
|
+
def setUp(self):
|
|
58
|
+
self.temp = tempfile.TemporaryDirectory()
|
|
59
|
+
self.addCleanup(self.temp.cleanup)
|
|
60
|
+
self.root = Path(self.temp.name)
|
|
61
|
+
self.source = self.root / "iris_classifier"
|
|
62
|
+
(self.source / "1").mkdir(parents=True)
|
|
63
|
+
(self.source / "1" / "model.onnx").write_bytes(b"onnx model")
|
|
64
|
+
(self.source / "config.pbtxt").write_text('name: "iris_classifier"')
|
|
65
|
+
|
|
66
|
+
def test_save_and_load_preserve_repository_and_flavor(self):
|
|
67
|
+
destination = self.root / "saved"
|
|
68
|
+
triton.save_model(str(self.source) + "/", destination)
|
|
69
|
+
|
|
70
|
+
self.assertEqual((destination / "model/1/model.onnx").read_bytes(), b"onnx model")
|
|
71
|
+
self.assertEqual((destination / "model/config.pbtxt").read_text(), 'name: "iris_classifier"')
|
|
72
|
+
saved = Model.load(destination / "MLmodel")
|
|
73
|
+
self.assertEqual(saved.flavors["triton"], {"data": "model", "model_name": "iris_classifier"})
|
|
74
|
+
|
|
75
|
+
with patch.object(triton, "download_artifacts", return_value=str(destination)):
|
|
76
|
+
self.assertEqual(triton.load_model("models:/iris-serving/1"), destination / "model")
|
|
77
|
+
|
|
78
|
+
def test_log_model_forwards_registry_name_to_mlflow(self):
|
|
79
|
+
info = object()
|
|
80
|
+
with (
|
|
81
|
+
patch.dict(sys.modules, {"mlflow_triton_control.triton": triton}),
|
|
82
|
+
patch.object(Model, "log", return_value=info) as log,
|
|
83
|
+
):
|
|
84
|
+
result = triton.log_model(self.source, registered_model_name="iris-serving")
|
|
85
|
+
self.assertIs(result, info)
|
|
86
|
+
self.assertEqual(log.call_args.kwargs["registered_model_name"], "iris-serving")
|
|
87
|
+
self.assertEqual(log.call_args.kwargs["flavor_name"], "triton")
|
|
88
|
+
self.assertIs(log.call_args.kwargs["flavor"], triton)
|
|
89
|
+
self.assertEqual(log.call_args.kwargs["triton_model_path"], self.source)
|
|
90
|
+
|
|
91
|
+
def test_rejects_missing_version_and_symbolic_links(self):
|
|
92
|
+
(self.source / "1" / "model.onnx").unlink()
|
|
93
|
+
(self.source / "1").rmdir()
|
|
94
|
+
with self.assertRaisesRegex(MlflowException, "numbered version"):
|
|
95
|
+
triton.save_model(self.source, self.root / "saved")
|
|
96
|
+
(self.source / "1").mkdir()
|
|
97
|
+
(self.source / "1" / "model.onnx").symlink_to(self.source / "config.pbtxt")
|
|
98
|
+
with self.assertRaisesRegex(MlflowException, "symbolic links"):
|
|
99
|
+
triton.save_model(self.source, self.root / "saved")
|
|
100
|
+
|
|
101
|
+
def test_rejects_non_triton_mlflow_model(self):
|
|
102
|
+
destination = self.root / "saved"
|
|
103
|
+
destination.mkdir()
|
|
104
|
+
Model().save(destination / "MLmodel")
|
|
105
|
+
with patch.object(triton, "download_artifacts", return_value=str(destination)):
|
|
106
|
+
with self.assertRaisesRegex(MlflowException, "no triton flavor"):
|
|
107
|
+
triton.load_model("models:/sklearn/1")
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
if __name__ == "__main__":
|
|
111
|
+
unittest.main()
|