Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mgw/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from . import _jax_config # noqa: F401 - configure JAX before any OTT/JAX imports
from .models import PhiModel, PhiModelFFN, train_phi, train_phi_pro
from .geometry import pullback_metric_field, knn_graph, geodesic_distances, pairwise_squared_geodesic
from .gw import gw_distance, solve_gw
Expand Down
8 changes: 8 additions & 0 deletions mgw/_jax_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""Project-level JAX runtime defaults."""

import os

# Disable JAX GPU memory preallocation so OTT/JAX does not reserve most GPU
# memory in MGW workflows that also use PyTorch; set this env var before
# importing MGW to opt out and restore JAX's default allocator behavior.
os.environ.setdefault("XLA_PYTHON_CLIENT_PREALLOCATE", "false")
6 changes: 6 additions & 0 deletions mgw/gw.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import os

import numpy as np

# Match MGW package defaults even if this module is imported directly: avoid
# JAX/OTT preallocating most GPU memory alongside PyTorch workloads.
os.environ.setdefault("XLA_PYTHON_CLIENT_PREALLOCATE", "false")
from ott.problems.quadratic import quadratic_problem
from ott.solvers.linear.sinkhorn import Sinkhorn
from ott.solvers.quadratic.gromov_wasserstein import GromovWasserstein
Expand Down