Metadata-Version: 2.4
Name: mimiry-serverless
Version: 0.7.0
Summary: Run Python functions on Mimiry GPUs: @function, .remote(), .map() and run()
Author: Mimiry ApS
License-Expression: Apache-2.0
License-File: LICENSE
License-File: NOTICE
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: POSIX :: Linux
Classifier: Operating System :: MacOS
Project-URL: Homepage, https://github.com/mimiry-com/mimiry-sdk-python
Project-URL: Source, https://github.com/mimiry-com/mimiry-sdk-python
Requires-Python: >=3.11
Requires-Dist: mimiry-sdk>=0.7.0,<0.8
Requires-Dist: cloudpickle>=3.0
Description-Content-Type: text/markdown

# mimiry-serverless

Run Python functions on Mimiry GPUs. Installed by `pip install mimiry`, with `mimiry-sdk`.

```python
from mimiry_serverless import function, Image

@function(gpu="RTX_48G_PCIe", image=Image.python().pip_install("torch"))
def matmul(n: int) -> float:
    import torch
    a = torch.rand(n, n, device="cuda")
    return float((a @ a).sum())

print(matmul.remote(4096))        # a new session, one call, the session ends
print(matmul.map([1024, 2048]))   # one session, every item through it
print(matmul.last_run)            # the session, its GPU, what it cost
```

`run("nvidia-smi")` runs a shell command and returns its exit code and output.

Sign-in is the `mimiry` command's: `mimiry auth --host platform` once, or `configure(host=, key=)`.

## Choosing the machine

`gpu` (types, as `mimiry availability` lists them), `family`, `min_vram` (GB), `gpu_count`,
`location`, `max_rate` (EUR per hour). With none of them: the cheapest GPU.

## The image and Python

A function travels as a cloudpickle blob, which loads only on the Python version that sent it.
The default image is Docker Hub's `python:<your version>-slim`; `Image.python().pip_install(...)`
adds packages when the container starts. Another image must run your Python version: declare it
with `.python_version("3.12")` and a mismatch is refused before anything is paid for.

A function defined in your script travels with its code. One imported from your own package
travels by name, so the package must be in the image (or `cloudpickle.register_pickle_by_value`).

## Results, and what is trusted

Loading a pickled result runs the code it names, and a result is written by whatever runs in the
container. So a result loads only if every type in it is allowed:

- always: plain data (numbers, strings, bytes, lists, dicts, tuples, sets, dates, decimals,
  UUIDs), NumPy arrays and Torch tensors (they arrive on the CPU);
- the classes in the function's return annotation (`-> Result`), with a dataclass's field types;
- the classes in `result_types=[...]`.

Anything else is refused with `ResultTypeRefused`, naming the type. `trust_results=True` loads
anything: use it only if you trust everything that runs in the container.

## How it works

The session starts with a small command that installs nothing from the network but what the image
asks for. The function, its arguments and the result travel only over SSH through the Mimiry
gateway, with the session's host key checked: never in the session request, so the platform does
not store them. Each call runs in a worker of its own, so a dropped connection does not lose it.
The session ends after the call, or after 10 minutes without one.
