Download code/tt_embgemma/device.py from changh95/embeddinggemma-2: direct link, hf CLI and curl.
- Browser
- Download file 1.44 kB
-
https://huggingface.co/changh95/embeddinggemma-2/resolve/main/code/tt_embgemma/device.py
- Command line
-
hf download hf://changh95/embeddinggemma-2/code/tt_embgemma/device.py
-
curl -L -o device.py https://huggingface.co/changh95/embeddinggemma-2/resolve/main/code/tt_embgemma/device.py
1.44 kB
| # SPDX-License-Identifier: Apache-2.0 | |
| """Opening the p150 (vendored ``ttaw.device``): ETH dispatch by default (12 x 10 compute grid), the grid is read at | |
| runtime, ``EMBGEMMA_DISPATCH`` / ``_NUM_CQS`` / ``_L1_SMALL`` / ``_TRACE_REGION`` / ``_WORKER_L1_SIZE`` and | |
| ``TT_DEVICE_ID`` override per process. Importing has no side effects.""" | |
| from __future__ import annotations | |
| import contextlib | |
| import dataclasses | |
| from typing import Any, Dict, Iterator, Optional | |
| from .ttaw.device import DeviceConfig, close_device, compute_grid, describe_device # noqa: F401 | |
| ENV_PREFIX = "EMBGEMMA" | |
| DEVICE_DEFAULTS: Dict[str, Any] = { | |
| "num_command_queues": 1, | |
| "l1_small_size": 32 << 10, # audio subsample conv2d config tensors | |
| "trace_region_size": 256 << 20, # one trace per (stage, bucket) | |
| } | |
| def device_config(**overrides: Any) -> DeviceConfig: | |
| config = DeviceConfig.from_env(ENV_PREFIX, **DEVICE_DEFAULTS) | |
| return dataclasses.replace(config, **{k: v for k, v in overrides.items() if v is not None}) | |
| def open_device(device_id: Optional[int] = None, *, dispatch: Optional[str] = None, **overrides: Any): | |
| return device_config(device_id=device_id, dispatch=dispatch, **overrides).open() | |
| def device_session(device_id: Optional[int] = None, **overrides: Any) -> Iterator[Any]: | |
| device = open_device(device_id, **overrides) | |
| try: | |
| yield device | |
| finally: | |
| close_device(device) | |