Installation¶
M3 is installed from PyPI as m3-sc and imported as import m3. It is
tested on Python 3.10 – 3.12 on Linux and macOS.
TL;DR
Step 1 — Create an isolated environment¶
On Windows, run the conda / mamba commands in the Anaconda Prompt (or in a
shell where conda init has been run).
Step 2 — PyTorch (usually nothing to do)¶
M3's training engine runs on PyTorch, which pip install m3-sc pulls in
automatically as a dependency of captum. Most people can skip straight to
Step 3.
Nothing to do — Step 3 brings PyTorch with it. On Apple Silicon, M3 runs on the CPU backend.
What Step 3 brings depends on the platform:
- Linux — the
torchwheel on PyPI is already a CUDA build, so usually there is nothing to do. It is built for the CUDA version current at that PyTorch release, which needs a recent NVIDIA driver. - Windows — the
torchwheel on PyPI is CPU-only, so install a CUDA build yourself.
To install a CUDA build (Windows, or Linux with an older driver), take the command from the PyTorch selector for your platform and CUDA version, and run it before Step 3 — pip will then keep the build you chose. It has this form:
The highest CUDA version your driver supports is shown in the header of
nvidia-smi.
Verify, once Step 3 is done:
On a machine with an NVIDIA GPU, False here means the installed torch is a
CPU build or needs a newer driver than you have — install a matching CUDA build
as in the NVIDIA GPU tab.
Step 3 — Install M3¶
Installing m3-sc pulls in its runtime dependencies:
| Package | Used for |
|---|---|
numpy |
array math |
scipy |
sparse count matrices |
pandas |
metadata I/O |
anndata |
.h5ad reading |
h5py |
paper-format expression matrix I/O |
scikit-learn |
internal PCA / scaling in the engine |
scanpy |
neighbours / UMAP used by the engine |
tqdm |
training progress bars |
captum |
integrated-gradients attribution — brings torch with it |
PyTorch therefore arrives automatically, so a plain pip install m3-sc gives you
everything the training engine needs. Install torch yourself only if you want a
build matched to a specific CUDA version (Step 2).
Step 4 — Verify the install¶
Expected output: the installed version number. If a version prints, the API is reachable.
The demo dataset used throughout the tutorials is built into the wheel — no download or preprocessing step:
import m3
data = m3.datasets.liu_demo()
print(data)
# Dataset(n_cells=30534, batches=['B1', 'B2', 'B3'], modalities=[rna:1000, adt:192])
You're ready for the Quickstart.
Installing the R package¶
The R interface lives in the same repository (the m3-r/ directory) and wraps
the identical engine, so R and Python produce the same results. It installs
straight from GitHub — no Bioconductor/CRAN step:
You do not install Python or PyTorch yourself — on first use the R package provisions its own engine environment through basilisk. Verify:
See the R tutorials and the R API.
GPU notes¶
- If a CUDA-enabled
torchis detected, M3 uses it automatically — no.to("cuda")calls anywhere in the user-facing API. - For the built-in demo, CPU is fine. For full real-data scale (≥ 100 k cells,
max_epochs=500), a GPU saves roughly 10× wall time. - On Apple Silicon, M3 runs on the CPU backend — the engine selects CUDA when a GPU is present and otherwise CPU (MPS acceleration is not yet enabled).
Input data format¶
M3 takes raw counts — it normalises internally, so do not pre–log-normalise.
The input is one count matrix per modality (RNA and/or ADT and/or ATAC) plus
per-cell metadata with a batch column and a condition / phenotype column.
The donor-level tasks also need a cell-type column and a
donor / sample column. Read the data with
m3.read_h5ad or
m3.from_anndata, which take one file or AnnData
per modality and match the cells by name, or with
m3.read_h5 for paper-format files. Count arrays
already in one cell order go to m3.read_matrix,
and datasets built separately are combined with
m3.concat. See the API reference for exact signatures,
and Use your own data for a worked example.
Troubleshooting¶
Stuck on install?
- GPU / CUDA mismatch error at
import torch -
The pre-built
torchwheel does not match your CUDA toolkit. Reinstall via the PyTorch selector with the correct--index-url. condasolver hangs for > 2 minutes-
Switch to mamba:
conda install -n base -c conda-forge mamba, then re-create the env withmamba. Orconda config --set solver libmambato use libmamba globally. ModuleNotFoundError: No module named 'torch'when youimport m3-
m3-scnormally brings PyTorch with it, so this points at a broken or partial environment.pip install --force-reinstall torchinto the same environment, and check you are not in a different env than you installed into. - Still broken?
-
Open an issue and paste the output of
python -c "import m3; print(m3.__version__)"plus yourpip freeze.
Next: the Quickstart.