# Device selection

*Estimated read time: 3 minutes*

Pick where your model runs by selecting a **device type** (runtime + hardware) and optionally a **device index**. This guide focuses on device selection. For performance tuning (e.g., latency, throughput, etc.), see the advanced guides.

## Model JSON info

Each model package defines a default and supported device list in its JSON file:

{% code overflow="wrap" %}

```json
"DEVICE": [
  {
    "DeviceType": "METIS",
    "RuntimeAgent": "AXELERA",
    "SupportedDeviceTypes": "AXELERA/METIS"
  }
]
```

{% endcode %}

**Interpretation**:

* **Default**: `METIS` and `AXELERA` — derived from `DeviceType` and `RuntimeAgent`
* **Supported list**: `AXELERA/METIS`.

At runtime, this shows up as `model.supported_device_types` (read‑only).

## Device discovery

{% stepper %}
{% step %}
**Load the model**

{% code overflow="wrap" %}

```python
from degirum_tools import ModelSpec
model_spec = ModelSpec(
    model_name="…",
    zoo_url="degirum/axelera",
    inference_host_address="@local",
)
model = model_spec.load_model()
```

{% endcode %}
{% endstep %}

{% step %}
**Check supported device types**

{% code overflow="wrap" %}

```python
print(
    "supported:", model.supported_device_types
)  # e.g., ['AXELERA/METIS']
```

{% endcode %}
{% endstep %}

{% step %}
**Check what's available on this machine**

* CLI: `degirum sys-info` → lists discovered hardware per runtime
* Or, after choosing a type, read `model.devices_available` (read‑only indices for that type)

{% code overflow="wrap" %}

```python
model.device_type = "AXELERA/METIS"  # Pick a type to query
print("available indices:", model.devices_available)  # e.g., [0]
```

{% endcode %}
{% endstep %}
{% endstepper %}

## Choose a device type

You can set `device_type` to pass a string for a fixed type (deterministic) or as a list (to allow fallbacks). If a list is used, PySDK picks the first available.

**Deterministic pick** (fixed device type):

{% code overflow="wrap" %}

```python
# Lock to one runtime/hardware type
model_spec = ModelSpec(
    ..., model_properties={"device_type": "AXELERA/METIS"}
)
model = model_spec.load_model()
```

{% endcode %}

**Graceful fallback** (try multiple types in order):

{% code overflow="wrap" %}

```python
# Prefer Metis, then CPU as a last resort
model_spec = ModelSpec(
    ...,
    model_properties={
        "device_type": ["AXELERA/METIS", "CPU"]
    },
)
model = model_spec.load_model()  # First available wins
```

{% endcode %}

{% hint style="info" %}
Use exact strings from `model.supported_device_types` to avoid typos.
{% endhint %}

### (Optional) Pin a specific device index

On multi‑card systems, you can set `devices_selected` to choose which device ID to use:

{% code overflow="wrap" %}

```python
model.device_type = "AXELERA/METIS"
print(model.devices_available)  # e.g., [0]
model.devices_selected = [0]  # Choose the first available card
```

{% endcode %}

* `devices_available`: read‑only list of indices for the current `device_type`
* `devices_selected`: writable list of indices to use

## Set‑once vs. tweak‑later

* **Set once in** `ModelSpec`: Use `device_type` (single or list) to ensure consistent, team‑wide defaults.
* **Tweak later on the** `model`: Use `devices_selected` to pin a card, or switch `device_type` interactively while exploring.

## Common pitfalls

* **String mismatch**: Use only values from `model.supported_device_types`.
* **“No device found”**: Check hardware presence using `degirum sys-info`. Consider fallback lists for `device_type`.
* **Wrong device used**: Set `devices_selected = [index]` after choosing `device_type`.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.degirum.com/axelera/intermediate-guides/model-properties/device-selection.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
