Skip to content
20 changes: 11 additions & 9 deletions frameworks/MLNet/exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ def run(dataset: Dataset, config: TaskConfig):
train_time_in_seconds = config.max_runtime_seconds
sub_command = config.type

# set up MODELBUILDER_AUTOML
MODELBUILDER_AUTOML = config.framework_params.get('automl_type', 'NNI')
os.environ['MODELBUILDER_AUTOML'] = MODELBUILDER_AUTOML

artifacts = config.framework_params.get('_save_artifacts', [])
tmpdir = tempfile.mkdtemp()
Expand All @@ -50,18 +47,23 @@ def run(dataset: Dataset, config: TaskConfig):
label = dataset.target.index
train_dataset_path = dataset.train.data_path('csv')
test_dataset_path = dataset.test.data_path('csv')

log.info(f'train dataset: {train_dataset_path}')
log.info(f'test dataset: {test_dataset_path}')
log.info(f'train dataset: {train_dataset_path}')

cmd = (f"{mlnet} {sub_command}"
f" --dataset {train_dataset_path} --test-dataset {test_dataset_path} --train-time {train_time_in_seconds}"
f" --dataset {train_dataset_path} --train-time {train_time_in_seconds}"
f" --label-col {label} --output {os.path.dirname(output_dir)} --name {config.fold}"
f" --verbosity q --log-file-path {log_path}")

with Timer() as training:
run_cmd(cmd)
log.info(f"Finished fit in {training.duration}s.")
try:
run_cmd(cmd , _live_output_=True)
log.info(f"Finished fit in {training.duration}s.")
except:
log.info(f"error: please visit {log_path} for more information")
with open(log_path, 'r') as f:
for line in f:
log.info(line)

train_result_json = os.path.join(output_dir, '{}.mbconfig'.format(config.fold))
if not os.path.exists(train_result_json):
Expand All @@ -70,7 +72,7 @@ def run(dataset: Dataset, config: TaskConfig):
with open(train_result_json, 'r') as f:
json_str = f.read()
mb_config = json.loads(json_str)
model_path = os.path.join(output_dir, f"{config.fold}.zip")
model_path = os.path.join(output_dir, f"{config.fold}.mlnet")
output_prediction_path = os.path.join(log_dir, "prediction.txt") # keeping this in log dir as it contains useful error when prediction fails
models_count = len(mb_config['RunHistory']['Trials'])
# predict
Expand Down
11 changes: 7 additions & 4 deletions frameworks/MLNet/setup.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
HERE=$(dirname "$0")
MLNET='mlnet'
MLNET_PACKAGE='mlnet-linux-x64'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it be possible to adjust this so it also works on ARM (and preferably also macos)? For example by storing the result of:

import sys
import platform
platform = {"linux": "linux", "darwin": "osx"}.get(sys.platform)
machine =  {"arm64": "arm64", "x86_64": "x64"}.get(platform.machine())
print(f"mlnet-{platform}-{machine}")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep that would work. You might need to target to different platform for arm64 and x64 though

available packages

  • mlnet-linux-x64
  • mlnet-linux-arm64
  • mlnet-macos-x64
  • mlnet-macos-arm64 (for m-seriese chip)

Copy link
Collaborator

@PGijsbers PGijsbers Aug 26, 2023

Choose a reason for hiding this comment

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

That should be in the above script already :) and based on the installation docs the mac abbreviation is osx instead of macos.

VERSION=${1:-"latest"}

DOTNET_INSTALL_DIR="$HERE/lib"
Expand All @@ -21,13 +21,16 @@ if [[ ! -x "$MLNET" ]]; then
if [[ ! -x "$DOTNET" ]]; then
wget -P "$DOTNET_INSTALL_DIR" https://dot.net/v1/dotnet-install.sh
chmod +x "$DOTNET_INSTALL_DIR/dotnet-install.sh"
"$DOTNET_INSTALL_DIR/dotnet-install.sh" -c Current --install-dir "$DOTNET_INSTALL_DIR" -Channel 3.1 --verbose
"$DOTNET_INSTALL_DIR/dotnet-install.sh" -c Current --install-dir "$DOTNET_INSTALL_DIR" -Channel 6.0 --verbose
fi
$DOTNET tool install mlnet --add-source "$SOURCE" --version "$VERSION" --tool-path "$DOTNET_INSTALL_DIR"
$DOTNET tool install $MLNET_PACKAGE --add-source "$SOURCE" --version "$VERSION" --tool-path "$DOTNET_INSTALL_DIR"
else
$DOTNET tool update mlnet --add-source "$SOURCE" --version "$VERSION" --tool-path "$DOTNET_INSTALL_DIR"
$DOTNET tool update $MLNET_PACKAGE --add-source "$SOURCE" --version "$VERSION" --tool-path "$DOTNET_INSTALL_DIR"
fi

export DOTNET_ROOT="$DOTNET_INSTALL_DIR"

# enable predict command in mlnet
export MLNetCLIEnablePredict=True

$MLNET --version | grep + | sed -e "s/\(.?*\)+.*/\1/" >> "${HERE}/.setup/installed"