a802f59f55
- cmd/fn/doctor.go - cmd/fn/main.go - cpp/apps/primitives_gallery/playground/tables/CMakeLists.txt - cpp/apps/primitives_gallery/playground/tables/data_table.cpp - cpp/apps/primitives_gallery/playground/tables/data_table_logic.cpp - cpp/apps/primitives_gallery/playground/tables/data_table_logic.h - cpp/apps/primitives_gallery/playground/tables/self_test.cpp - cpp/apps/primitives_gallery/playground/tables/tql.cpp - cpp/apps/primitives_gallery/playground/tables/viz.cpp - cpp/apps/primitives_gallery/playground/tables/viz.h - ... Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2.6 KiB
2.6 KiB
name, kind, lang, domain, version, purity, signature, description, tags, uses_functions, uses_types, returns, returns_optional, error_type, imports, params, output, tested, tests, test_file_path, file_path
| name | kind | lang | domain | version | purity | signature | description | tags | uses_functions | uses_types | returns | returns_optional | error_type | imports | params | output | tested | tests | test_file_path | file_path | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| torch_device_select | function | py | ml | 1.0.0 | impure | def torch_device_select(preference: str = 'auto') -> str | Selecciona el torch device optimo segun preferencia y disponibilidad real del hardware. 'auto' elige CUDA > MPS > CPU. Para preferencias explicitas valida disponibilidad y hace fallback a CPU con warnings.warn. |
|
|
false | error_go_core |
|
string de device listo para torch: 'cuda:0', 'cuda:N', 'mps' o 'cpu'. Nunca lanza excepcion — fallback a 'cpu' con warning si el device solicitado no esta disponible. | true |
|
python/functions/ml/tests/test_torch_device_select.py | python/functions/ml/torch_device_select.py |
Ejemplo
from ml.torch_device_select import torch_device_select
# Deteccion automatica (recomendado)
device = torch_device_select() # "cuda:0" o "mps" o "cpu"
# Forzar CPU para reproducibilidad
device = torch_device_select("cpu") # siempre "cpu"
# Preferencia explicita con fallback automatico
device = torch_device_select("cuda") # "cuda:0" o "cpu" + warning
# Uso tipico al cargar un modelo
import torch
device_str = torch_device_select("auto")
model = MyModel().to(torch.device(device_str))
Comparacion con gliner_load_model
gliner_load_model usa internamente _resolve_device con la misma logica
CUDA/CPU. torch_device_select extiende ese patron con:
- Soporte MPS (Apple Silicon M1/M2/M3).
- Seleccion de GPU especifica (
cuda:N). - Fallback con
warnings.warnen vez de silencio.
Notas
- No levanta excepcion si torch no esta instalado: todos los helpers internos capturan ImportError y tratan el device como no disponible.
warnings.warnen vez de logging para no imponer dependencia de logging al caller.- MPS requiere torch >= 1.12 y macOS 12.3+. En sistemas Linux/Windows
torch.backends.mpspuede no existir — el helper lo maneja conhasattr. - impure: depende del estado del hardware y de las librerias instaladas.