L i7 @ddlmZddlZddlmZ d dedededefdZy) )AnyN)_get_device_indexdeviceoptional allow_cpureturnct|tr|St|trtj|}t|tjr;|r|j dvr+t d||j dk7rt d|tjjs0t|tjjr |jSt|||S)aGet the device index from :attr:`device`, which can be a torch.device object, a Python integer, or ``None``. If :attr:`device` is a torch.device object, returns the device index if it is a XPU device. Note that for a XPU device without a specified index, i.e., ``torch.device('xpu')``, this will return the current default XPU device if :attr:`optional` is ``True``. If :attr:`allow_cpu` is ``True``, CPU devices will be accepted and ``-1`` will be returned in this case. If :attr:`device` is a Python integer, it is returned as is. If :attr:`device` is ``None``, this will return the current default XPU device if :attr:`optional` is ``True``. )xpucpuz'Expected a xpu or cpu device, but got: r z Expected a xpu device, but got: ) isinstanceintstrtorchrtype ValueErrorjit is_scriptingr idx_torch_get_device_index)rrrs V/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/torch/xpu/_utils.pyrr s"&# &#f%&%,,' {{.0 #J6(!STT [[E !?xHI I 99 ! ! # feii.. /::  "68Y ??)FF)typingrr torch._utilsrrboolr rrrsA F