flowml 0.1.0__py3-none-any.whl
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.
- flowml/__init__.py +19 -0
- flowml/models/__init__.py +14 -0
- flowml/models/base.py +89 -0
- flowml/models/pytorch/__init__.py +9 -0
- flowml/models/pytorch/architectures/lstm.py +74 -0
- flowml/models/pytorch/architectures/mlp.py +45 -0
- flowml/models/pytorch/architectures/transformer.py +137 -0
- flowml/models/pytorch/base.py +272 -0
- flowml/models/pytorch/drivers/lstm_autoregressive.py +220 -0
- flowml/models/pytorch/drivers/lstm_direct_regressor.py +180 -0
- flowml/models/pytorch/drivers/mlp_regressor.py +180 -0
- flowml/models/pytorch/drivers/transformer_regressor.py +192 -0
- flowml/models/pytorch/utils.py +175 -0
- flowml/models/xgboost/__init__.py +7 -0
- flowml/models/xgboost/regressor.py +91 -0
- flowml/pipefill.py +160 -0
- flowml/tensorboard.py +44 -0
- flowml/utils.py +71 -0
- flowml-0.1.0.dist-info/LICENSE +201 -0
- flowml-0.1.0.dist-info/METADATA +214 -0
- flowml-0.1.0.dist-info/RECORD +22 -0
- flowml-0.1.0.dist-info/WHEEL +4 -0
flowml/utils.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import numpy.typing as npt
|
|
3
|
+
from sklearn.model_selection import train_test_split
|
|
4
|
+
from typing import Tuple
|
|
5
|
+
from pandas import DataFrame
|
|
6
|
+
|
|
7
|
+
from flowdapt.lib.logger import get_logger
|
|
8
|
+
|
|
9
|
+
logger = get_logger(__name__)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def make_train_test_datasets(
|
|
13
|
+
features, labels, weight_factor, data_params
|
|
14
|
+
) -> Tuple[npt.ArrayLike, npt.ArrayLike, npt.ArrayLike,
|
|
15
|
+
npt.ArrayLike, npt.ArrayLike, npt.ArrayLike]:
|
|
16
|
+
"""
|
|
17
|
+
Wrapper for SKLearn's train_test_split()
|
|
18
|
+
"""
|
|
19
|
+
weights = set_weights_higher_recent(len(features), weight_factor)
|
|
20
|
+
|
|
21
|
+
(
|
|
22
|
+
train_features,
|
|
23
|
+
test_features,
|
|
24
|
+
train_labels,
|
|
25
|
+
test_labels,
|
|
26
|
+
train_weights,
|
|
27
|
+
test_weights,
|
|
28
|
+
) = train_test_split(
|
|
29
|
+
features,
|
|
30
|
+
labels,
|
|
31
|
+
weights,
|
|
32
|
+
**data_params
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
return train_features, test_features, train_labels, test_labels, train_weights, test_weights
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def set_weights_higher_recent(num_weights: int, wfactor: float) -> npt.ArrayLike:
|
|
39
|
+
"""
|
|
40
|
+
Set weights so that recent data is more heavily weighted during
|
|
41
|
+
training than older data.
|
|
42
|
+
"""
|
|
43
|
+
if wfactor == 0:
|
|
44
|
+
weights = np.ones(num_weights)
|
|
45
|
+
else:
|
|
46
|
+
weights = np.exp(-np.arange(num_weights) / (wfactor * num_weights))[::-1]
|
|
47
|
+
return weights
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def reduce_dataframe_footprint(df: DataFrame) -> DataFrame:
|
|
51
|
+
"""
|
|
52
|
+
Ensure all values are float32 in the incoming dataframe.
|
|
53
|
+
:param df: Dataframe to be converted to float/int 32s
|
|
54
|
+
:return: Dataframe converted to float/int 32s
|
|
55
|
+
"""
|
|
56
|
+
|
|
57
|
+
logger.debug(f"Memory usage of dataframe is "
|
|
58
|
+
f"{df.memory_usage().sum() / 1024**2:.2f} MB")
|
|
59
|
+
|
|
60
|
+
df_dtypes = df.dtypes
|
|
61
|
+
for column, dtype in df_dtypes.items():
|
|
62
|
+
if dtype == np.float64:
|
|
63
|
+
df_dtypes[column] = np.float32
|
|
64
|
+
elif dtype == np.int64:
|
|
65
|
+
df_dtypes[column] = np.int32
|
|
66
|
+
df = df.astype(df_dtypes)
|
|
67
|
+
|
|
68
|
+
logger.debug(f"Memory usage after optimization is: "
|
|
69
|
+
f"{df.memory_usage().sum() / 1024**2:.2f} MB")
|
|
70
|
+
|
|
71
|
+
return df
|
|
@@ -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 2024 Emergent Methods
|
|
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,214 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: flowml
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: The machine learning components designed for use in Flowdapt.
|
|
5
|
+
License: Apache-2.0
|
|
6
|
+
Author: Emergent Methods
|
|
7
|
+
Author-email: contact@emergentmethods.ai
|
|
8
|
+
Requires-Python: >=3.11,<4.0
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Environment :: Web Environment
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
21
|
+
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
|
22
|
+
Classifier: Topic :: System :: Distributed Computing
|
|
23
|
+
Classifier: Topic :: Utilities
|
|
24
|
+
Requires-Dist: cloudpickle (==2.2.0)
|
|
25
|
+
Requires-Dist: datasieve (>=0.1.6,<0.2.0)
|
|
26
|
+
Requires-Dist: flowdapt (>=0.1.0,<0.2.0)
|
|
27
|
+
Requires-Dist: nvidia-cublas-cu11 (==11.10.3.66) ; sys_platform == "linux"
|
|
28
|
+
Requires-Dist: nvidia-cuda-cupti-cu11 (==11.7.101) ; sys_platform == "linux"
|
|
29
|
+
Requires-Dist: nvidia-cuda-nvrtc-cu11 (==11.7.99) ; sys_platform == "linux"
|
|
30
|
+
Requires-Dist: nvidia-cuda-runtime-cu11 (==11.7.99) ; sys_platform == "linux"
|
|
31
|
+
Requires-Dist: nvidia-cudnn-cu11 (==8.5.0.96) ; sys_platform == "linux"
|
|
32
|
+
Requires-Dist: nvidia-cufft-cu11 (==10.9.0.58) ; sys_platform == "linux"
|
|
33
|
+
Requires-Dist: nvidia-curand-cu11 (==10.2.10.91) ; sys_platform == "linux"
|
|
34
|
+
Requires-Dist: nvidia-cusolver-cu11 (==11.4.0.1) ; sys_platform == "linux"
|
|
35
|
+
Requires-Dist: nvidia-cusparse-cu11 (==11.7.4.91) ; sys_platform == "linux"
|
|
36
|
+
Requires-Dist: nvidia-nccl-cu11 (==2.14.3) ; sys_platform == "linux"
|
|
37
|
+
Requires-Dist: nvidia-nvtx-cu11 (==11.7.91) ; sys_platform == "linux"
|
|
38
|
+
Requires-Dist: pandas (>=2.0.2,<3.0.0)
|
|
39
|
+
Requires-Dist: pynvml (>=11.5.0,<12.0.0)
|
|
40
|
+
Requires-Dist: scikit-learn (>=1.2.0,<2.0.0)
|
|
41
|
+
Requires-Dist: tensorboard (>=2.12.0,<3.0.0)
|
|
42
|
+
Requires-Dist: torch (==2.0.1)
|
|
43
|
+
Requires-Dist: xgboost (>=1.7.2,<2.0.0)
|
|
44
|
+
Description-Content-Type: text/markdown
|
|
45
|
+
|
|
46
|
+
# flowml
|
|
47
|
+
|
|
48
|
+
flowml is a python package built for supplying time-series forecasting models in a large scale adaptive modeling environment. In particular, flowml is built to be used with [flowdapt](https://docs.flowdapt.ai), a platform for adaptive modeling. Flowdapt has an optimized approach to cluster memory handling which is supported by all models in this library. This optimized cluster-memory approach enables rapid inferencing, quick re-training, cheap concept-drift-detection, and easy hyperparameter tuning. Currently, the library provides models for:
|
|
49
|
+
|
|
50
|
+
- LSTM direct regression (PyTorchLSTMDirect)
|
|
51
|
+
- LSTM Autoregressive forecasting (PyTorchLSTMAutoregressive)
|
|
52
|
+
- Transformer based regression (PyTorchTransformer)
|
|
53
|
+
- MLP regression (PyTorchMLPRegressor)
|
|
54
|
+
- Gradient boosted decision tree (XGBoostRegressor) regression
|
|
55
|
+
|
|
56
|
+
and the structure enables easy addition of new models or tweaking of the existing ones.
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
## Usage
|
|
60
|
+
|
|
61
|
+
flowml can be imported from the `flowml` package and used as a normal python package:
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
from flowml.models import PyTorchLSTMDirect
|
|
65
|
+
|
|
66
|
+
model = PyTorchLSTMDirect(
|
|
67
|
+
input_features=200,
|
|
68
|
+
hidden_dim=64,
|
|
69
|
+
output_features=6,
|
|
70
|
+
num_layers=2,
|
|
71
|
+
dropout=0.2,
|
|
72
|
+
batch_size=32,
|
|
73
|
+
epochs=10
|
|
74
|
+
)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
which will define the LSTM model. Next, it can be called with a set of training data, following the SKLearn API:
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
x = np.random.rand(100, 200)
|
|
81
|
+
y = np.random.rand(100, 6)
|
|
82
|
+
model.fit(x, y)
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
the fitted model can then be used to make inferences on new data:
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
x = np.random.rand(10, 200)
|
|
89
|
+
y_hat = model.predict(x)
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Usage with cluster memory and distributed storage
|
|
93
|
+
|
|
94
|
+
flowml models are optimized to be stored on distributed storage or in Flowdapt's cluster memory. Typically this is as simple as:
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
from flowdapt.compute import object_store
|
|
98
|
+
|
|
99
|
+
object_store.put(model, "model_name")
|
|
100
|
+
model = object_store.get("model_name")
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
which would allow a model to be quickly accessed from anywhere in a Flowdapt cluster. The model can be saved to the distributed storage using the `artifact_only` argument:
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
object_store.put(model, "model_name", artifact_only=True)
|
|
107
|
+
model = object_store.get("model_name", artifact_only=True)
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Usage with the PipeFill
|
|
111
|
+
|
|
112
|
+
The PipeFill object is designed to easily contain, move, and organize models in the Flowdapt cluster. The need arises when thousands of heterogeneous models need to be trained, inferenced, stored, and tuned. In many cases, each model has its own unique data processing methods (e.g. scaling, outlier detection, dimensionality reduction [details here](pipeline.md)). Many of these data processing methods require auxillary data such as the training data itself and trained models (e.g. SVM).
|
|
113
|
+
|
|
114
|
+
The flowml `PipeFill` object is designed to organize all these auxillary objects, persist them to disk, and ensure they are properly coordinated between training and inferencing. The `PipeFill` also has helper functions for quickly creating/storing train/test data.
|
|
115
|
+
|
|
116
|
+
Typically, a train stage would instantiate the `PipeFill` object and start building and attaching objects to it. For example, we use helper function `make_pipe_fill` to create a `PipeFill` object:
|
|
117
|
+
|
|
118
|
+
```python
|
|
119
|
+
from flowml.pipefill import PipeFill
|
|
120
|
+
from datasieve.pipeline import Pipeline
|
|
121
|
+
import datasieve.transforms as ds
|
|
122
|
+
from flowdapt.compute import object_store
|
|
123
|
+
from sklearn.preprocessing import MinMaxScaler
|
|
124
|
+
|
|
125
|
+
def train_stage(*args):
|
|
126
|
+
|
|
127
|
+
# create the PipeFill object which instantiates the flowml.XGBoostRegressor
|
|
128
|
+
# automatically internally
|
|
129
|
+
pf = PipeFill(
|
|
130
|
+
name_str="descriptive_pipefill_name",
|
|
131
|
+
namespace="namespace",
|
|
132
|
+
model_str="flowml.models.XGBoostRegressor",
|
|
133
|
+
model_train_params=model_train_parameters,
|
|
134
|
+
data_split_params=data_split_parameters,
|
|
135
|
+
extras=extras
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
X = np.random.rand(100, 200)
|
|
139
|
+
y = np.random.rand(100, 6)
|
|
140
|
+
|
|
141
|
+
# helper function to automatically split the train and test datasets inside the
|
|
142
|
+
# pipefill and create the eval_set
|
|
143
|
+
X, y, w, Xt, yt, wt = mlutils.make_train_test_datasets()
|
|
144
|
+
|
|
145
|
+
# make the data preprocessing pipeline dict containing all the params that the user
|
|
146
|
+
# wants to pass to each step. They can miss them if they dont want to pass values
|
|
147
|
+
# (use defaults)
|
|
148
|
+
fitparams: dict[str, dict] = {"raw_scaler": {}}
|
|
149
|
+
pf.feature_pipeline = Pipeline([
|
|
150
|
+
("raw_scaler", ds.SKLearnWrapper(MinMaxScaler())),
|
|
151
|
+
("detect_constants", ds.VarianceThreshold(threshold=0)),
|
|
152
|
+
],
|
|
153
|
+
fitparams)
|
|
154
|
+
|
|
155
|
+
# fit the feature pipeline to the features and transform them in one call
|
|
156
|
+
X, y, w = pf.feature_pipeline.fit_transform(X, y, w)
|
|
157
|
+
# transform the test set using the fitted pipeline
|
|
158
|
+
Xt, yt, wt = pf.feature_pipeline.transform(Xt, yt, wt)
|
|
159
|
+
|
|
160
|
+
# the labels require a separate pipeline (the objects are fit in a the label parameter
|
|
161
|
+
# space.)
|
|
162
|
+
pf.target_pipeline = Pipeline([
|
|
163
|
+
("scaler", ds.SKLearnWrapper(MinMaxScaler()))
|
|
164
|
+
], fitparams)
|
|
165
|
+
|
|
166
|
+
y, _, _ = pf.target_pipeline.fit_transform(y)
|
|
167
|
+
yt, _, _ = pf.target_pipeline.transform(yt)
|
|
168
|
+
|
|
169
|
+
eval_set = pf.make_eval_set()
|
|
170
|
+
|
|
171
|
+
pf.model.fit(X, y, eval_set=eval_set)
|
|
172
|
+
|
|
173
|
+
pf.set_trained_timestamp()
|
|
174
|
+
|
|
175
|
+
object_store.put(pf, pf.name_str)
|
|
176
|
+
|
|
177
|
+
return
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
???+ note ""
|
|
181
|
+
Here we use the DataSieve `Pipeline` object, but details can be found [here](https://github.com/emergentmethods/datasieve).
|
|
182
|
+
|
|
183
|
+
We see how the `feature_pipeline` and `target_pipeline` are both fit and attached to the `pf` object. The `PipeFill` object is then saved to disk with helper function `save_pipefill()`. This object is now sitting on the disk, ready to be loaded when any other stage/workflow may need it. For example, an inferencing stage would load the `PipeFill`:
|
|
184
|
+
|
|
185
|
+
```python
|
|
186
|
+
from flowdapt.compute import object_store
|
|
187
|
+
def inference_stage(*args):
|
|
188
|
+
|
|
189
|
+
# look for the pipefill in the cluster memory
|
|
190
|
+
pf = object_store.get("descriptive_pipefill_name")
|
|
191
|
+
|
|
192
|
+
x = np.random.rand(10, 200)
|
|
193
|
+
|
|
194
|
+
# use the pipeline that was fit in train_stage to transform the features
|
|
195
|
+
Xprime, _, _ = pf.feature_pipeline.transform(x)
|
|
196
|
+
|
|
197
|
+
preds = pf.model.predict(Xprime)
|
|
198
|
+
|
|
199
|
+
# inverse transform the targets using the fit pipeline
|
|
200
|
+
preds, _, _ = pf.target_pipeline.inverse_transform(preds.reshape(-1, 1))
|
|
201
|
+
|
|
202
|
+
return preds
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
## Installation
|
|
208
|
+
|
|
209
|
+
For normal use users can install flowctl via pip:
|
|
210
|
+
```bash
|
|
211
|
+
pip install flowml
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
flowml/__init__.py,sha256=hsbQB_hOBH3rLr4cSXKeLqsira3kAU1f2mguU66sbCk,672
|
|
2
|
+
flowml/models/__init__.py,sha256=hKCWoVXPfRPCX7B8hi_35ace03D5Q1Nwxf9GgWelc9k,541
|
|
3
|
+
flowml/models/base.py,sha256=nVWp-OZydUkeoX-rv0lrTX8NRFQSX3SEHJB6CivMyUA,2648
|
|
4
|
+
flowml/models/pytorch/__init__.py,sha256=nOhAWHTghjHCaTJPYWs67AAKljsJlU3tLMr0ItQCjbo,337
|
|
5
|
+
flowml/models/pytorch/architectures/lstm.py,sha256=HJvPFjAQ5FuZPwtqz3VpShlXljK0hdwB9h3MpY-6frA,2551
|
|
6
|
+
flowml/models/pytorch/architectures/mlp.py,sha256=s8teCKgsZqdNjD9m8c_3tUy00KKyInMn_pAscsR2Qxs,1502
|
|
7
|
+
flowml/models/pytorch/architectures/transformer.py,sha256=Crg5AWI7MeZl0FewVNrFaonsYAi4j4h44WJfzoPJA6k,5569
|
|
8
|
+
flowml/models/pytorch/base.py,sha256=WnYtowUO4f5pe32DcDLbsT788CWOrAcFW7u5jZVPK1g,9927
|
|
9
|
+
flowml/models/pytorch/drivers/lstm_autoregressive.py,sha256=pE6QHJv8_LEQ1nOYnOsR3W0HQkbhWGB2IXqF-NU4XGo,8275
|
|
10
|
+
flowml/models/pytorch/drivers/lstm_direct_regressor.py,sha256=FTYWQV9ONj72b_HSWEAvKrOhxjubh28S4uHRnwho4SY,6676
|
|
11
|
+
flowml/models/pytorch/drivers/mlp_regressor.py,sha256=d01iDgvHlGaOEDUlp_csrl7266sJbxOI6mfswIvX6mk,6490
|
|
12
|
+
flowml/models/pytorch/drivers/transformer_regressor.py,sha256=vxyeTEr6m_Cir2wXhNvanCZM5ca4o8kpkkk2gNMx9Dw,6789
|
|
13
|
+
flowml/models/pytorch/utils.py,sha256=Zai_3cXaGULmrQl06GQQi4m_kiI_MxurFov1_HOeJBM,6020
|
|
14
|
+
flowml/models/xgboost/__init__.py,sha256=mCH7_K27o35ODjS0XfNr29TnPVGeNgad_pBdiFlWo5g,150
|
|
15
|
+
flowml/models/xgboost/regressor.py,sha256=rgcaqrjnrDqzbAAwx16zzJrTlm9TKXQtajnmXfznuF8,3089
|
|
16
|
+
flowml/pipefill.py,sha256=jeTrgPUaQI05apYaQxBtQtGe5a7zBgt1SbFXFmoXOzY,5665
|
|
17
|
+
flowml/tensorboard.py,sha256=3tR70IE2Ls5lHtdPHUYA9ru-ToE2l9kNw9Jkpffj3Iw,1450
|
|
18
|
+
flowml/utils.py,sha256=H79LgQV94xZ-ZPtpNHDv7NcLrqm6qO6VeUcdh8pkp_M,2019
|
|
19
|
+
flowml-0.1.0.dist-info/LICENSE,sha256=BY49ytuIAu1ENssv_H-487qf-QI0MHjArhTL7dWZIic,11346
|
|
20
|
+
flowml-0.1.0.dist-info/METADATA,sha256=KlDHwmu03BJdmtIpg6HH_-aaF2WTbTiy9J0oAh8wqWM,8597
|
|
21
|
+
flowml-0.1.0.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
|
22
|
+
flowml-0.1.0.dist-info/RECORD,,
|