---
title: SetTensor接口
description: "该接口用于设置Tensor。"
url: https://www.hiascend.com/document/detail/zh/mindie/latest/mindiellm/llmdev/mindie_llm0064.html
sourcePath: /source/zh/mindie/310/mindiellm/llmdev/mindie_llm0064.html
indexId: 24d82c7ea9dcc1d1068cda53fbf3c15cfd52c6475380c139bc540e96597b501358
---
# SetTensor接口

#### 接口功能

该接口用于设置Tensor。


#### 接口格式

```
void SetTensor(const std::string& tensorName, TensorPtr &tensor)
```


#### 接口参数

| 参数 | 是否必选 | 说明 | 取值要求 |
| --- | --- | --- | --- |
| tensorName | 是 | Tensor名称。 | 合法的string类型。 |
| tensor | 是 | Tensor数据。 | 合法的InferTensor类型，参考InferTensor。 |


#### 使用样例

构造一个请求对象，为请求设置一个Tensor名称为"INPUT_IDS"，类型为TYPE_INT64，Shape为{1,2}的Tensor。

```
mindie_llm::InferRequestId runtimeReqId(0);
std::shared_ptr<mindie_llm::InferRequest> runtimeRequest(runtimeReqId);
std::string name = "INPUT_IDS";
mindie_llm::InferDataType dataType = mindie_llm::InferDataType::TYPE_INT64;
std::vector<int64_t> dataShape = {1, 2};
auto inputsTensor = std::make_shared<mindie_llm::InferTensor>(name, dataType, dataShape);
runtimeRequest->SetTensor(name, inputsTensor);
```


#### 返回值

无。
