Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 36 additions & 31 deletions functions/src/auto_trainer/auto_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,30 +67,14 @@ def _get_dataframe(
Classification tasks.
:param drop_columns: str/int or a list of strings/ints that represent the column names/indices to drop.
"""
store_uri_prefix, _ = mlrun.datastore.parse_store_uri(dataset.artifact_url)

# Getting the dataset:
if mlrun.utils.StorePrefix.FeatureVector == store_uri_prefix:
label_columns = label_columns or dataset.meta.status.label_column
context.logger.info(f"label columns: {label_columns}")
# FeatureVector case:
try:
fv = mlrun.datastore.get_store_resource(dataset.artifact_url)
dataset = fv.get_offline_features(drop_columns=drop_columns).to_dataframe()
except AttributeError:
# Leave here for backwards compatibility
dataset = fs.get_offline_features(
dataset.meta.uri, drop_columns=drop_columns
).to_dataframe()

elif not label_columns:
context.logger.info(
"label_columns not provided, mandatory when dataset is not a FeatureVector"
)
raise ValueError

elif isinstance(dataset, (list, dict)):
# Check if dataset is list/dict first (before trying to access artifact_url)
if isinstance(dataset, (list, dict)):
# list/dict case:
if not label_columns:
context.logger.info(
"label_columns not provided, mandatory when dataset is not a FeatureVector"
)
raise ValueError
dataset = pd.DataFrame(dataset)
# Checking if drop_columns provided by integer type:
if drop_columns:
Expand All @@ -103,17 +87,38 @@ def _get_dataframe(
)
raise ValueError
dataset.drop(drop_columns, axis=1, inplace=True)

else:
# simple URL case:
dataset = dataset.as_df()
if drop_columns:
if all(col in dataset for col in drop_columns):
dataset = dataset.drop(drop_columns, axis=1)
else:
# Dataset is a DataItem with artifact_url (URI or FeatureVector)
store_uri_prefix, _ = mlrun.datastore.parse_store_uri(dataset.artifact_url)

# Getting the dataset:
if mlrun.utils.StorePrefix.FeatureVector == store_uri_prefix:
label_columns = label_columns or dataset.meta.status.label_column
context.logger.info(f"label columns: {label_columns}")
# FeatureVector case:
try:
fv = mlrun.datastore.get_store_resource(dataset.artifact_url)
dataset = fv.get_offline_features(drop_columns=drop_columns).to_dataframe()
except AttributeError:
# Leave here for backwards compatibility
dataset = fs.get_offline_features(
dataset.meta.uri, drop_columns=drop_columns
).to_dataframe()
else:
# simple URL case:
if not label_columns:
context.logger.info(
"not all of the columns to drop in the dataset, drop columns process skipped"
"label_columns not provided, mandatory when dataset is not a FeatureVector"
)
raise ValueError
dataset = dataset.as_df()
if drop_columns:
if all(col in dataset for col in drop_columns):
dataset = dataset.drop(drop_columns, axis=1)
else:
context.logger.info(
"not all of the columns to drop in the dataset, drop columns process skipped"
)

return dataset, label_columns

Expand Down
76 changes: 38 additions & 38 deletions functions/src/auto_trainer/function.yaml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions functions/src/auto_trainer/item.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ labels:
author: Iguazio
maintainers: []
marketplaceType: ''
mlrunVersion: 1.7.0
mlrunVersion: 1.10.0
name: auto_trainer
platformVersion: 3.5.0
spec:
Expand All @@ -23,4 +23,4 @@ spec:
kind: job
requirements: []
url: ''
version: 1.8.0
version: 1.9.0
3 changes: 2 additions & 1 deletion functions/src/auto_trainer/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pandas
scikit-learn<1.4.0
scikit-learn~=1.5.2
lightgbm
xgboost<2.0.0
plotly
13 changes: 10 additions & 3 deletions functions/src/auto_trainer/test_auto_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
("sklearn.linear_model.LinearRegression", "regression"),
("sklearn.ensemble.RandomForestClassifier", "classification"),
("xgboost.XGBRegressor", "regression"),
("xgboost.XGBClassifier", "classification"),
("lightgbm.LGBMRegressor", "regression"),
("lightgbm.LGBMClassifier", "classification")
]

REQUIRED_ENV_VARS = [
Expand Down Expand Up @@ -78,11 +81,15 @@ def _assert_train_handler(train_run):


@pytest.mark.parametrize("model", MODELS)
@pytest.mark.skipif(
condition=not _validate_environment_variables(),
reason="Project's environment variables are not set",
)
def test_train(model: Tuple[str, str]):
dataset, label_columns = _get_dataset(model[1])
is_test_passed = True

project = mlrun.new_project("auto-trainer-test", context="./")
project = mlrun.get_or_create_project("auto-trainer-test", context="./")
fn = project.set_function("function.yaml", "train", kind="job", image="mlrun/mlrun")

train_run = None
Expand Down Expand Up @@ -119,7 +126,7 @@ def test_train_evaluate(model: Tuple[str, str]):
dataset, label_columns = _get_dataset(model[1])
is_test_passed = True
# Importing function:
project = mlrun.new_project("auto-trainer-test", context="./")
project = mlrun.get_or_create_project("auto-trainer-test", context="./")
fn = project.set_function("function.yaml", "train", kind="job", image="mlrun/mlrun")
temp_dir = tempfile.mkdtemp()

Expand Down Expand Up @@ -172,7 +179,7 @@ def test_train_predict(model: Tuple[str, str]):
df = pd.read_csv(dataset)
sample = df.head().drop("labels", axis=1).values.tolist()
# Importing function:
project = mlrun.new_project("auto-trainer-test", context="./")
project = mlrun.get_or_create_project("auto-trainer-test", context="./")
fn = project.set_function("function.yaml", "train", kind="job", image="mlrun/mlrun")
temp_dir = tempfile.mkdtemp()

Expand Down
82 changes: 41 additions & 41 deletions functions/src/describe/function.yaml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions functions/src/describe/item.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ labels:
author: Iguazio
maintainers: []
marketplaceType: ''
mlrunVersion: 1.7.0
mlrunVersion: 1.10.0
name: describe
platformVersion: 3.5.3
spec:
Expand All @@ -21,4 +21,4 @@ spec:
kind: job
requirements: []
url: ''
version: 1.4.0
version: 1.5.0
2 changes: 1 addition & 1 deletion functions/src/describe/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
scikit-learn~=1.0.2
scikit-learn~=1.5.2
plotly~=5.23
pytest~=7.0.1
matplotlib~=3.5.1
Expand Down
18 changes: 9 additions & 9 deletions functions/src/gen_class_data/function.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
metadata:
categories:
- data-generation
tag: ''
name: gen-class-data
categories:
- data-generation
verbose: false
spec:
description: Create a binary classification sample dataset and save.
default_handler: gen_class_data
entry_points:
gen_class_data:
lineno: 22
has_varargs: false
has_kwargs: false
parameters:
- name: context
Expand Down Expand Up @@ -48,7 +50,6 @@ spec:
- name: sk_params
doc: additional parameters for `sklearn.datasets.make_classification`
default: {}
lineno: 22
doc: 'Create a binary classification sample dataset and save.

If no filename is given it will default to:
Expand All @@ -59,14 +60,13 @@ spec:
Additional scikit-learn parameters can be set using **sk_params, please see
https://scikit-learn.org/stable/modules/generated/sklearn.datasets.make_classification.html
for more details.'
has_varargs: false
name: gen_class_data
command: ''
disable_auto_mount: false
image: mlrun/mlrun
build:
origin_filename: ''
functionSourceCode: IyBDb3B5cmlnaHQgMjAxOSBJZ3VhemlvCiMKIyBMaWNlbnNlZCB1bmRlciB0aGUgQXBhY2hlIExpY2Vuc2UsIFZlcnNpb24gMi4wICh0aGUgIkxpY2Vuc2UiKTsKIyB5b3UgbWF5IG5vdCB1c2UgdGhpcyBmaWxlIGV4Y2VwdCBpbiBjb21wbGlhbmNlIHdpdGggdGhlIExpY2Vuc2UuCiMgWW91IG1heSBvYnRhaW4gYSBjb3B5IG9mIHRoZSBMaWNlbnNlIGF0CiMKIyAgICAgaHR0cDovL3d3dy5hcGFjaGUub3JnL2xpY2Vuc2VzL0xJQ0VOU0UtMi4wCiMKIyBVbmxlc3MgcmVxdWlyZWQgYnkgYXBwbGljYWJsZSBsYXcgb3IgYWdyZWVkIHRvIGluIHdyaXRpbmcsIHNvZnR3YXJlCiMgZGlzdHJpYnV0ZWQgdW5kZXIgdGhlIExpY2Vuc2UgaXMgZGlzdHJpYnV0ZWQgb24gYW4gIkFTIElTIiBCQVNJUywKIyBXSVRIT1VUIFdBUlJBTlRJRVMgT1IgQ09ORElUSU9OUyBPRiBBTlkgS0lORCwgZWl0aGVyIGV4cHJlc3Mgb3IgaW1wbG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zZXRzLm1ha2VfY2xhc3NpZmljYXRpb25gCiAgICAiIiIKICAgIGZlYXR1cmVzLCBsYWJlbHMgPSBtYWtlX2NsYXNzaWZpY2F0aW9uKAogICAgICAgIG5fc2FtcGxlcz1uX3NhbXBsZXMsCiAgICAgICAgbl9mZWF0dXJlcz1tX2ZlYXR1cmVzLAogICAgICAgIHdlaWdodHM9d2VpZ2h0LAogICAgICAgIG5fY2xhc3Nlcz1rX2NsYXNzZXMsCiAgICAgICAgcmFuZG9tX3N0YXRlPXJhbmRvbV9zdGF0ZSwKICAgICAgICAqKnNrX3BhcmFtcykKCiAgICAjIG1ha2UgZGF0YWZyYW1lcywgYWRkIGNvbHVtbiBuYW1lcywgY29uY2F0ZW5hdGUgKFgsIHkpCiAgICBYID0gcGQuRGF0YUZyYW1lKGZlYXR1cmVzKQogICAgaWYgbm90IGhlYWRlcjoKICAgICAgICBYLmNvbHVtbnMgPSBbImZlYXRfIiArIHN0cih4KSBmb3IgeCBpbiByYW5nZShtX2ZlYXR1cmVzKV0KICAgIGVsc2U6CiAgICAgICAgWC5jb2x1bW5zID0gaGVhZGVyCgogICAgeSA9IHBkLkRhdGFGcmFtZShsYWJlbHMsIGNvbHVtbnM9W2xhYmVsX2NvbHVtbl0pCiAgICBkYXRhID0gcGQuY29uY2F0KFtYLCB5XSwgYXhpcz0xKQoKICAgIGNvbnRleHQubG9nX2RhdGFzZXQoa2V5LCBkZj1kYXRhLCBmb3JtYXQ9ZmlsZV9leHQsIGluZGV4PUZhbHNlKQo=
code_origin: ''
command: ''
image: mlrun/mlrun
default_handler: gen_class_data
disable_auto_mount: false
kind: job
verbose: false
4 changes: 2 additions & 2 deletions functions/src/gen_class_data/item.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ labels:
author: Iguazio
maintainers: []
marketplaceType: ''
mlrunVersion: 1.7.0
mlrunVersion: 1.10.0
name: gen_class_data
platformVersion: 3.5.3
spec:
Expand All @@ -21,4 +21,4 @@ spec:
kind: job
requirements: []
url: ''
version: 1.3.0
version: 1.4.0
2 changes: 1 addition & 1 deletion functions/src/gen_class_data/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pandas
scikit-learn==1.0.2
scikit-learn~=1.5.2
5 changes: 4 additions & 1 deletion functions/src/gen_class_data/test_gen_class_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,7 @@ def test_gen_class_data():
local=True,
artifact_path="./artifacts",
)
assert os.path.isfile(run.status.artifacts[0]['spec']['target_path']), 'dataset is not available'
# In local mode, artifacts are in function-name/iteration subdirectory
# Default key is "classifier-data" (can be overridden in params)
dataset_path = "./artifacts/test-gen-class-data-gen-class-data/0/classifier-data.csv"
assert os.path.isfile(dataset_path), f'dataset is not available at {dataset_path}'
74 changes: 37 additions & 37 deletions functions/src/onnx_utils/function.yaml

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions functions/src/onnx_utils/item.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ labels:
author: Iguazio
maintainers: []
marketplaceType: ''
mlrunVersion: 1.7.2
mlrunVersion: 1.10.0
name: onnx_utils
platformVersion: 3.5.0
spec:
Expand All @@ -30,13 +30,13 @@ spec:
- tqdm~=4.67.1
- tensorflow~=2.19.0
- tf_keras~=2.19.0
- torch~=2.6.0
- torchvision~=0.21.0
- torch~=2.8.0
- torchvision~=0.23.0
- onnx~=1.17.0
- onnxruntime~=1.19.2
- onnxoptimizer~=0.3.13
- onnxmltools~=1.13.0
- tf2onnx~=1.16.1
- plotly~=5.23
url: ''
version: 1.3.0
version: 1.4.0
Loading