How to Get Started with Auto-PyTorch: Your Guide to Automated Deep Learning

Jun 16, 2021 | Data Science

Welcome to the world of Auto-PyTorch, a powerful framework designed for those venturing into the realms of automated deep learning (AutoDL). Whether you are working with tabular data or tackling time series forecasting, Auto-PyTorch combines the best of both worlds: optimizing neural network architectures alongside hyperparameter tuning! In this article, we’ll walk through the installation, workflow, and code examples to help you get started.

What is Auto-PyTorch?

Auto-PyTorch is primarily aimed at simplifying the model selection and fine-tuning process for classification, regression, and forecasting tasks handled by neural networks. This is achieved through a set of algorithms and techniques that automatically adjust the architecture and hyperparameters of models tailored to your dataset.

Installation: Getting Started

To dive into Auto-PyTorch, follow these installation steps:

Using PyPI

  • To install the core package, run:
  • pip install autoPyTorch
  • If you need features for time series forecasting, use the following command:
  • pip install autoPyTorch[forecasting]

Manual Installation with Anaconda

For a more controlled setup, using Anaconda is recommended:

  • First, clone the Auto-PyTorch repository and initialize the automl_common submodule:
  • git submodule update --init --recursive
  • Create a new conda environment:
  • conda create -n auto-pytorch python=3.8
  • Activate the environment:
  • conda activate auto-pytorch
  • Install the needed dependencies:
  • conda install swig
  • Finally, run:
  • python setup.py install

Understanding the Workflow

The workflow of Auto-PyTorch can be understood through the following steps, likening it to a chef preparing a gourmet meal:

  • Data: The ingredients you provide – the better the quality, the better the meal.
  • Portfolio: A carefully curated collection of possible recipes (models) that have been proven to work well with various datasets.
  • Evaluate Baselines: Trying out basic recipes before moving onto complex ones.
  • SMAC Optimization: Experimenting with different cooking methods (configurations) until you achieve the perfect dish (model performance).
  • Build Best Ensemble: Combining the best flavors (models) into a final gourmet plate (ensemble model).

Code Example: Tabular Classification

Let’s get into some hands-on coding! Here’s a simple code snippet for setting up a tabular classification task:

from autoPyTorch.api.tabular_classification import TabularClassificationTask
import sklearn.model_selection
import sklearn.datasets
import sklearn.metrics

X, y = sklearn.datasets.load_digits(return_X_y=True)
X_train, X_test, y_train, y_test = sklearn.model_selection.train_test_split(X, y, random_state=1)

api = TabularClassificationTask()
api.search(X_train=X_train, y_train=y_train, X_test=X_test, y_test=y_test, optimize_metric=accuracy, total_walltime_limit=300, func_eval_time_limit_secs=50)

y_pred = api.predict(X_test)
score = api.score(y_pred, y_test)
print("Accuracy score:", score)

Code Example: Time Series Forecasting

For Time Series Forecasting, here’s how you can go about it:

from autoPyTorch.api.time_series_forecasting import TimeSeriesForecastingTask
from sktime.datasets import load_longley

targets, features = load_longley()
forecasting_horizon = 3
y_train = [targets[:-forecasting_horizon]]
y_test = [targets[-forecasting_horizon:]]
X_train = [features[:-forecasting_horizon]]
X_test = [features[-forecasting_horizon:]]

api = TimeSeriesForecastingTask()
api.search(X_train=X_train, y_train=y_train, X_test=X_test, optimize_metric=mean_MAPE_forecasting, n_prediction_steps=forecasting_horizon, memory_limit=16 * 1024, total_walltime_limit=60)

y_pred = api.predict(test_sets)
score = api.score(y_pred, y_test)
print("Forecasting score:", score)

Troubleshooting Tips

If you encounter issues while setting up or running Auto-PyTorch, here are some common troubleshooting ideas:

  • Ensure that you have properly installed all dependencies based on your installation method.
  • Check the documentation for any updates or changes in the API.
  • If you’re running into compatibility issues, consider reviewing the changes introduced in version updates.
  • For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

Conclusion

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

With Auto-PyTorch, you’re equipped to harness automated deep learning for your projects. Dive in, and unleash the power of AI!

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox