modular / modular/modular

[Magic]: magic/max does not support usage in google colab notebooks

Open
#4,025 0 comments 0 reactions 1 assignee View on GitHub

@zbowling is already working on this.

Since Feb 26, 2025.

enhancement magic modular-repo
Dominant language
Mojo
Stars
29.8k
Forks
3.2k
PR merge metrics
No merged PRs in 30d

Description

This was originally filed by guidorice at https://github.com/modular/max/issues/223. With the merge of the max, mojo repos, file the bug here.

Background

https://colab.research.google.com is widely used in data science and AI because of it's pay-as-you go model using a variety of TPU or NVIDIA GPU's. A common use case is going to be to install MAX and python packages into the notebook environment on colab. Couple of other key points:

  • Colab does not seem to support switching notebook kernels via a menu item. This makes it fundamentally different than jupyter notebook which is self hosted or run locally.
  • Every tutorial in existence for colab notebooks seems to start off with a notebook cell with the shell command ! pip install my-packages ... into the existing python env. Many scientific and AI packages are pre-installed, for example fastai, torch and transformers.

Reproduce steps

Go to https://docs.modular.com/max/python/get-started and follow the steps, but in a colab notebook. I am using Colab Pro, which also has a terminal window:

$ curl -ssL https://magic.modular.com | bash
$ magic init roberta-project && cd roberta-project
$ magic add max "numpy<2.0"
$ magic add --pypi "torch==2.2.2" "transformers==4.40.1"
$ magic shell
$ python3 -c 'from max import engine; print(engine.__version__)'
24.5.0
$ python --version
Python 3.12.5

^ as you can see max python package is installed, and python 3.12 as well.

The problem is, all the packages are in a virtualenv, however this is not something the notebook can use!

To confirm, create a notebook cell and execute it (from the get-started doc):

from pathlib import Path

import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification

from max import engine

ModuleNotFoundError: No module named 'max'

The reason the other imports succeeded is because torch and transformers is pre-installed on colab instances.

Related issues

Suggestion

Enhance magic to support installing into the system python, something like:

magic add --global max

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.