我在 azureML Notebook 中工作,每当我尝试使用以下代码获取对计算实例的引用时:
from azureml.core import Workspace
ws = Workspace.from_config()
from azureml.core import ComputeTarget
compute = ComputeTarget(workspace =ws, name = "MyCompute")
我得到这个错误:
...
During handling of the above exception, another exception occurred:
UnboundLocalError Traceback (most recent call last)
/tmp/ipykernel_6497/1818551949.py in <module>
3 ws = Workspace.from_config()
4 from azureml.core import ComputeTarget
----> 5 compute = ComputeTarget(workspace =ws, name = "MyCompute")
/anaconda/envs/myenv/lib/python3.8/site-packages/azureml/core/compute/compute.py in __new__(cls, workspace, name)
85 elif compute_type == child._compute_type:
86 compute_target = super(ComputeTarget, cls).__new__(child)
---> 87 compute_target._initialize(workspace, compute_payload)
88 return compute_target
89 else:
/anaconda/envs/myenv/lib/python3.8/site-packages/azureml/core/compute/computeinstance.py in _initialize(self, workspace, obj_dict)
125
126 if not status.created_by_user_name:
--> 127 status.created_by_user_name = ComputeInstance._get_user_display_name(
128 self.workspace,
129 status.created_by_user_id,
/anaconda/envs/myenv/lib/python3.8/site-packages/azureml/core/compute/computeinstance.py in _get_user_display_name(workspace, user_id, tenant_id)
965 except Exception:
966 # Set the display name to None if the user is unauthorized to call graph api
--> 967 if resp.status_code in [401, 403]:
968 ComputeInstance._user_display_info[key] = None
969 return None
UnboundLocalError: local variable 'resp' referenced before assignment
顺便说一下,这是我正在使用的环境:
name: myenv
channels:
- conda-forge
- pytorch
- anaconda
- defaults
dependencies:
- python==3.8
- matplotlib
- numpy
- pytorch==1.8.0
- torchvision==0.9.0
- cpuonly
- pip
- pip:
- azureml-defaults
- opencv-python-headless
- 'git+https://github.com/facebookresearch/detectron2.git'
你们有什么解决方案或建议吗?
我先谢谢大家了!
注意:我删除了问题的第一部分,因为它似乎没有帮助,而且由于 stackoverflow 一直要求我为我的问题添加解释(或减少代码),所以我减少了错误消息......