Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tabular][bugfix] fix tabular NN working with _ray_predict_oof #2650

Merged
merged 2 commits into from
Jan 6, 2023

Conversation

liangfu
Copy link
Collaborator

@liangfu liangfu commented Jan 6, 2023

Issue #, if available:

from autogluon.tabular import TabularDataset, TabularPredictor

# Training time:
train_data = TabularDataset('https://autogluon.s3.amazonaws.com/datasets/Inc/train.csv')
train_data = train_data.head(500)  # subsample for faster demo
print(train_data.head())
label = 'class'  # specifies which column do we want to predict
save_path = 'ag_models/'  # where to save trained models

if os.path.exists(save_path):
    shutil.rmtree(save_path, ignore_errors=True)

predictor = TabularPredictor(label=label, path=save_path). \
    fit(train_data, presets='good_quality', time_limit=120)

Training with presets='good_quality' will result in an error.

The fundamental reason is that _ray_predict_oof would delete fold_model.model, see

def _ray_predict_oof(fold_model, X_val_fold, y_val_fold, time_train_end_fold,
                     num_cpus=-1, save_bag_folds=True):
    pred_proba = fold_model.predict_proba(X_val_fold, num_cpus=num_cpus)
    time_pred_end_fold = time.time()
    fold_model.predict_time = time_pred_end_fold - time_train_end_fold
    fold_model.val_score = fold_model.score_with_y_pred_proba(y=y_val_fold,
                                                              y_pred_proba=pred_proba)
    fold_model.reduce_memory_size(remove_fit=True, remove_info=False, requires_save=True)
    if not save_bag_folds:
        fold_model.model = None
    return fold_model, pred_proba

Therefore, loading the PyTorch model with torch.load(path + "net.params") would result in an error.

Description of changes:

The proposed change is to include the PyTorch model inside the pickle file (model.pkl), just like other models.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@github-actions
Copy link

github-actions bot commented Jan 6, 2023

Job PR-2650-23e1050 is done.
Docs are uploaded to http://autogluon-staging.s3-website-us-west-2.amazonaws.com/PR-2650/23e1050/index.html

@liangfu liangfu requested a review from Innixma January 6, 2023 18:49
@@ -276,7 +276,7 @@ def transform(self, X):

class TabularNeuralNetTorchOnnxCompiler:
name = "onnx"
save_in_pkl = False
save_in_pkl = True
Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting that this works now, I remember originally NN_TORCH wasn't serializable, but maybe that was NN_MXNET and we just kept that assumption when migrating. It could have also been some of the code that has since been removed that wasn't serializable. Either way, very nice that we can save it to pickle now.

Copy link
Contributor

@Innixma Innixma left a comment

Choose a reason for hiding this comment

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

LGTM!

@liangfu liangfu merged commit 7a12726 into autogluon:master Jan 6, 2023
@liangfu liangfu deleted the fix-good-quality-1 branch January 6, 2023 19:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants