PyMC Marketing Foundational Models
PyMC MFM (marketing foundational models) trains and runs amortized neural networks for marketing mix decomposition. A trained network reads one weekly time series (media spend, controls and the observed outcome) and returns posterior draws of each component's contribution: baseline, each channel, each control and unobserved factors. The network is trained on many simulated datasets, so a new dataset needs no model fitting.
This repository is the library. Trained weights are separate. A bundle is a folder with one trained network's weights. River-1 is PyMC Labs' trained network: load its bundle from the Hugging Face Hub, or run it on the hosted River API.
Status: alpha. The API can change between releases.
Documentation: see the Guide.
Installation
Python 3.13 or newer:
pip install pymc-mfm
uv add pymc-mfm # in a uv project
No trained weights are included.
- On Linux, pip and uv install the CUDA build of PyTorch, about 3 GB. On a machine
without a GPU, install the CPU build first:
pip install torch --index-url https://download.pytorch.org/whl/cpu. - PyPI has no PyTorch wheels for Intel Macs. There, install PyTorch from conda-forge first.
pymc-mfmis not on conda-forge yet. In a conda environment, install it with pip.- In a uv project, set
requires-python = ">=3.13"inpyproject.toml, because uv resolves for every Python version the project allows.
Quickstart
mfm.load opens a model and model.inference(context, query) runs it. context is the
history: one row per week with spend, controls and the observed outcome. query holds the
weeks to explain or forecast, starting the week after the history ends.
The example loads a bundle from ./models/my-model. If you have no bundle, replace that
line with one from the table below.
import numpy as np
import pandas as pd
import pymc_mfm as mfm
# Synthetic data: 104 weeks of history and an 8-week plan after it.
rng = np.random.default_rng(0)
weeks = pd.date_range("2024-11-11", periods=104, freq="7D")
tv = rng.gamma(4.0, 2_000.0, size=104)
search = rng.gamma(4.0, 1_500.0, size=104)
price = rng.normal(10.0, 0.3, size=104)
noise = rng.normal(0, 500, size=104)
sales = 40_000 + 0.8 * tv + 1.2 * search - 1_000 * (price - 10.0) + noise
history = pd.DataFrame({"week": weeks, "sales": sales, "tv": tv, "search": search, "price": price})
future = pd.DataFrame(
{
"week": pd.date_range(weeks[-1] + pd.Timedelta(weeks=1), periods=8, freq="7D"),
"tv": 8_000.0,
"search": 6_000.0,
"price": 10.0,
}
)
roles = {
"date_column": "week",
"target_column": "sales",
"channel_columns": ["tv", "search"],
"control_columns": ["price"],
}
model = mfm.load("./models/my-model", **roles) # a bundle folder; see the table below
result = model.inference(history, future, n_samples=100, random_seed=0)
result.plot.fit() # expected vs observed sales
result.plot.contributions_over_time() # weekly contribution of every component
result.idata # context and query draws in an xarray.DataTree
Change only the load call to choose the model and where it runs:
| Call | Runs | Needs |
|---|---|---|
mfm.load("./models/my-model", **roles) |
On your machine, from a bundle folder | The bundle |
mfm.load("river-1", **roles) |
On your machine, with River-1 weights from Hugging Face | Access to the PyMC Labs Hugging Face organization |
mfm.load("river-1", engine="hosted", **roles) |
On the hosted River API | An invitation: MFM_API_URL and MFM_API_KEY |
The River-1 quickstart notebook walks through this workflow. To call the River API directly for budget scenarios and backtests, see the River API guide.
Development
uv sync --locked
uv run --no-sync pytest -q -n 2 -m "not slow"
uv run ruff check . && uv run ruff format --check .
uv run --no-sync python scripts/check_public_boundary.py
This repository is public, history included: never commit trained weights, credentials,
user data or internal deployment names. Open pull requests against main;
AGENTS.md has the contributor rules.
Documentation site. docs/ is a Quarto project. With Quarto
CLI 1.11.9, run uv sync --locked --group docs, then uv run --no-sync quarto preview docs.
License
The code is licensed under Apache-2.0. Model weights are separate artifacts with their own licenses.
Metadata
Release files for pymc-mfm 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pymc_mfm-0.0.2.tar.gz | 2.7 MB | With provenance | Details for pymc_mfm-0.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pymc_mfm-0.0.2-py3-none-any.whl | Python 3 | none | any | Details for pymc_mfm-0.0.2-py3-none-any.whl |
Total release size: 3.2 MB
Release files / pymc_mfm-0.0.2.tar.gz
| Download URL | pymc_mfm-0.0.2.tar.gz |
|---|---|
| Size | 2.7 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1ca6253607e303f419fc99691871653b8883146751c07f089ad1b35ac646815f
|
|
BLAKE2b-256 checksum How to use checksums |
7debf35f7ce4ffa389ed930bcd8ede7b51d9cf862e5263803ce3b2615f4e69ff
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.
Transparency logRelease files / pymc_mfm-0.0.2-py3-none-any.whl
| Download URL | pymc_mfm-0.0.2-py3-none-any.whl |
|---|---|
| Size | 521.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d70cc37d7b2639a28268dc77e7f5f10aa88e42bf2b6008c0974de42c9ea86114
|
|
BLAKE2b-256 checksum How to use checksums |
e5cebed29791bf766f4365f6d4f28337cc884945458acf465a4850fb6e581feb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.
Transparency logSecurity for pymc-mfm 0.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for pymc_mfm-0.0.2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.