---
title: switch_role
description: "| 产品 | 是否支持 |"
url: https://www.hiascend.com/document/detail/zh/canncommercial/latest/others/llmdatadistdev/llmpr_42_0011.html
sourcePath: /source/zh/canncommercial/900/others/llmdatadistdev/llmpr_42_0011.html
indexId: a02e1dfeca32c75b816f41fe6df9aebd6cc881412829648475d8d881c510ede870
---
# switch_role

#### 产品支持情况

| 产品 | 是否支持 |
| --- | --- |
| Atlas 350 加速卡 | x |
| Atlas A3 训练系列产品 / Atlas A3 推理系列产品 | √ |
| Atlas A2 训练系列产品 / Atlas A2 推理系列产品 | √ |
| Atlas 200I/500 A2 推理产品 | x |
| Atlas 推理系列产品 | x |
| Atlas 训练系列产品 | x |


说明：针对 Atlas A2 训练系列产品 / Atlas A2 推理系列产品 ，仅支持Atlas 800I A2 推理服务器、A200I A2 Box 异构组件。


#### 函数功能

切换当前LLMDataDist的角色，建议仅在使用PagedAttention的场景使用。


#### 函数原型

```
switch_role(self, role: LLMRole, switch_options: Optional[Dict[str, str]] = None)
```


#### 参数说明

| 参数名称 | 数据类型 | 取值说明 |
| --- | --- | --- |
| role | LLMRole | 切换的目标角色。 |
| switch\_options | options: Dict[str, str] | 切换角色配置项。 可选参数，默认值为None。 切换为Prompt时需要设置，其中需包含listen\_ip\_info配置项。 |


#### 调用示例

```
from llm_datadist import LLMDataDist, LLMRole
llm_datadist = LLMDataDist(LLMRole.DECODER, 0)
switch_options = { 'llm.listenIpInfo': '127.0.0.1:26000' }
llm_datadist.switch_role(LLMRole.PROMPT, switch_options)
```


#### 返回值

- 正常情况下无返回值。
- 传入数据类型错误情况下会抛出TypeError或ValueError异常。
- 如果初始化LLMDataDist时LLMConfig未使能  enable_switch_role
，调用该接口则会抛出  LLMException
，status_code为LLM_FEATURE_NOT_ENABLED。
- 如果switch_role时存在残留链路资源，则会抛出  LLMException
，status_code为LLM_EXIST_LINK。
- 如果switch_role的目标role与当前role相同，则会抛出  LLMException
，status_code为LLM_PARAM_INVALID。
- 单进程多卡模式下，不支持调用该接口。


#### 约束说明

无
