如何使用MindSpore替换torch.distributions的Categorical函数
收藏回复举报
如何使用MindSpore替换torch.distributions的Categorical函数
发表于2024-02-23 08:43:13
0 查看

系统环境

硬件环境(Ascend/GPU/CPU): Ascend/GPU/CPU

MindSpore版本: mindspore=2.0.0

执行模式(PyNative/ Graph):不限

Python版本: Python=3.7

操作系统平台: 不限

报错信息

2.1问题描述

将pytorch转换成mindspore代码的时候,调用了pytorch.distributions的Categorical方法,这三行代码该怎么使用mindspore的方法进行呢。

2.2脚本信息

Torch实现方式如下:

import torch.nn.functional as F
from torch.distributions import Categorical
def sample_cycle_component(self, logits, output_type, random_ratio=0):
        action_index_local = Categorical(logits=logits).sample()
        prob_matrix = F.softmax(logits, dim=1)
        log_prob_matrix = F.log_softmax(logits, dim=1)

根因分析

******此处由用户填写******

解决方案

******此处由用户填写******

包含文字方案和最终脚本代码

请将正确的脚本打包并上传附件

我要发帖子