Tries JSON first. Falls back to legacy pickle ONLY for files named .pkl (so a non-JSON payload disguised as .json is refused rather than unpickled, since pickle can execute arbitrary code). Existing .pkl artifacts still load.
Args: config_fn: File path to load.
Returns: The deserialized [size, apply_reorder, target_spacing] list.
Return PatchConfig values as a JSON-native dictionary.
config may be a PatchConfig-like object or a mapping. Missing fields in historical mappings receive the current PatchConfig defaults. Set inference_only=True to omit training-only sampling, queue, and data-state settings.
Remove the torch.compile key prefix from a state dict, in place.
learn.save() on a compiled model writes keys prefixed with _orig_mod., which an uncompiled module cannot load.
Args: state_dict: A state dict, e.g. from torch.load. fastai checkpoints written with with_opt=True are {‘model’: …, ‘opt’: …}; pass the ‘model’ value. prefix: Key prefix to remove.
Returns: The same dict, so it can be passed straight to load_state_dict. A dict without the prefix is returned unchanged.
Return model with any torch.compile wrapper removed.
torch.compile(model) returns an OptimizedModule that holds the original module as _orig_mod alongside TorchDynamo state bound to the torch build that created it. A learner exported while compiled loads on any torch, but raises on the first forward pass under a different one. The returned module shares its weights with the wrapper.
Args: model: An nn.Module, or a fastai Learner whose .model is unwrapped in place.
Returns: The innermost nn.Module, or the same Learner that was passed in. A model that was never compiled is returned unchanged.
Note: Handles torch.compile(model). model.compile() compiles in place and leaves no wrapper to remove.
A FastAI callback for comprehensive MLflow experiment tracking.
This callback automatically logs hyperparameters, metrics, model artifacts, and configuration to MLflow during training. If a checkpoint callback (SaveModelCallback, EMACheckpoint, or any TrackerCallback with fname) is present, the best model checkpoint will also be logged as an artifact.
Create MLflow tracking callback with auto-extracted configuration.
This factory function automatically extracts configuration from the Learner, eliminating the need to manually specify parameters like size, transforms, loss function, etc.
Auto-extracts from Learner: - Preprocessing: apply_reorder, target_spacing, size/patch_size - Transforms: item_tfms or pre_patch_tfms - Training: loss_func, model architecture
Args: learn: fastai Learner instance experiment_name: MLflow experiment name. If None, uses model name. run_name: MLflow run name. If None, auto-generates with timestamp. auto_start: If True, auto-starts/stops MLflow run in before_fit/after_fit. model_name: Override the auto-extracted model name (used as the experiment name when experiment_name is None). model_spec: Required allow-listed architecture reconstruction specification. output_spec: Required patch-workflow output/decoding contract. inference_config: Required complete config for standard workflows; includes output. extra_params: Additional parameters to log (e.g., {‘dropout’: 0.5}). extra_tags: MLflow tags to set on the run. dataset_version: Optional annotation/dataset fingerprint for tracking. preprocessing_manifest: Optional manifest returned by preprocess_dataset(). Its dataset/cache identities are validated, tagged, and logged. sample_id_col: Optional stable identity column for split_version. By default, the raw image path is used when available. log_split: If True, hashes and logs actual fastai train/val membership.
Returns: ModelTrackingCallback ready to use with learn.fit()
Download explicitly selected Safetensors model artifacts from MLflow.
run_ids must map each stable member identifier to one immutable MLflow run ID. Experiment-name or latest-run discovery is intentionally unsupported: callers must declare exactly which trained models inference will use.
Launch and manage a local mlflow ui server from a notebook.
The UI’s lifetime is tied to the kernel: it is reaped when the interpreter exits, gracefully (via an atexit handler) or on a hard kill (via Linux PR_SET_PDEATHSIG, see [_die_with_parent](https://fastmonai.no/utils.html#_die_with_parent)), so closing/restarting the notebook never leaves an orphaned server holding the port. Call stop() to shut it down sooner. An externally-started UI is reused, not killed.