> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bioptimus.com/llms.txt
> Use this file to discover all available pages before exploring further.

# bioptimus.runtime.models.m_optimus

M-Optimus prediction server-side model.

Loads the exported M-Optimus spatial transcriptomics model. Accepts optional bulk RNA counts alongside the tile image.

In the two-stage pipeline, bulk RNA preprocessing and gene count validation happen during `prepare_sample` (Stage 1), so a malformed `bulk_rna` field fails only the individual request without affecting the batch.

## MOptimusModel

```python theme={null}
class MOptimusModel(checkpoint_name: str,
                    device: str = 'cuda',
                    model_root: Path = MODEL_ROOT,
                    assets_root: Path = ASSETS_ROOT)
```

M-Optimus prediction model (224x224, MPP 0.5).

Produces per-tile gene expression predictions. Optionally incorporates bulk RNA counts when provided in the request.

<ParamField body="checkpoint_name">
  Filename of the `.pt2` checkpoint.
</ParamField>

<ParamField body="device">
  Torch device string.
</ParamField>

<ParamField body="model_root">
  Directory containing the checkpoint.
</ParamField>

<ParamField body="assets_root">
  Directory containing gene set CSVs.
</ParamField>

***

#### input\_gene\_names

```python theme={null}
@property
def input_gene_names() -> List[str]
```

Ordered list of input (bulk RNA) Ensembl gene IDs.

***

#### output\_gene\_names

```python theme={null}
@property
def output_gene_names() -> List[str]
```

Ordered list of predicted output Ensembl gene IDs.

***

#### get\_metadata

```python theme={null}
def get_metadata() -> dict
```

Returns base metadata plus input and output gene sets.

**Returns**:

Dictionary with model info, gene sets, and I/O specs.

***

#### prepare\_sample

```python theme={null}
def prepare_sample(request: ModelRequest) -> PreparedSample
```

Deserializes tile image and validates bulk RNA per-sample.

Bulk RNA preprocessing and gene count validation happen here so that a single request with malformed RNA data fails with a per-request error (HTTP 400) and never enters the batch.

<ParamField body="request">
  Raw model request.
</ParamField>

**Returns**:

A [`PreparedSample`](/sdk-reference/runtime/server_model#preparedsample) with tile tensor and optional
bulk RNA tensor in `extra_tensors`.

**Raises**:

* `BioptimusValueError` - Tagged with `ErrorCode.RNA_SCHEMA_MISMATCH` if bulk RNA preprocessing fails or the gene count does not match the model panel. Subclasses `ValueError`, so it still maps to an HTTP 400 at the API boundary.
* `ValueError` - If the tile image is invalid (raised by the base class).

***

#### forward

```python theme={null}
def forward(requests: list[ModelRequest]) -> torch.Tensor
```

Runs M-Optimus inference with optional bulk RNA (legacy path).

<ParamField body="requests">
  List of tile requests with optional bulk RNA.
</ParamField>

**Returns**:

Model output tensor of shape `(N, num_output_genes)`.
