已合并
[bugfix] modify the yaml configuration of op kl_div. #2104
weixin_40805272创建于 2025年1月23日
[bugfix] modify the yaml configuration of op kl_div. #2104
已合并
从refs/pull/2104/head合入到master
共 2 个文件变更+10-0
| @@ -26,6 +26,7 @@ backward: | |||
| 26 | 26 | ||
| 27 | - name: kl_div(Tensor self, Tensor target, int reduction=Mean, *, bool log_target=False) -> Tensor | 27 | - name: kl_div(Tensor self, Tensor target, int reduction=Mean, *, bool log_target=False) -> Tensor |
| 28 | self: kl_div_backward(grad, self, target, reduction, log_target) | 28 | self: kl_div_backward(grad, self, target, reduction, log_target) |
| 29 | + target: non_differentiable | ||
| 29 | version: [v2.0, newest] | 30 | version: [v2.0, newest] |
| 30 | 31 | ||
| 31 | - name: l1_loss(Tensor self, Tensor target, int reduction=Mean) -> Tensor | 32 | - name: l1_loss(Tensor self, Tensor target, int reduction=Mean) -> Tensor |
| @@ -99,6 +99,15 @@ class TestKlDiv(TestCase): | |||
| 99 | npu_output = self.npu_op_exec(npu_input, npu_target, reduction) | 99 | npu_output = self.npu_op_exec(npu_input, npu_target, reduction) |
| 100 | self.assertRtolEqual(cpu_output.astype(np.float16), npu_output) | 100 | self.assertRtolEqual(cpu_output.astype(np.float16), npu_output) |
| 101 | 101 | ||
| 102 | + def test_kl_div_input_requires_grad_True(self): | ||
| 103 | + input_cpu = torch.tensor([0.2, 0.7, 0.1], requires_grad=True) | ||
| 104 | + target_cpu = torch.tensor([0., 1., 0.]) | ||
Z | |||
| 105 | + input_npu = input_cpu.npu() | ||
| 106 | + target_npu = target_cpu.npu() | ||
| 107 | + output_cpu = torch.nn.functional.kl_div(input_cpu, target_cpu, reduction='sum') | ||
| 108 | + output_npu = torch.nn.functional.kl_div(input_npu, target_npu, reduction='sum') | ||
| 109 | + self.assertEqual(output_cpu, output_npu) | ||
W 这里应该比的是npu和cpu的结果吧,怎么成是否为None了 ![]() ![]() | |||
| 110 | + | ||
| 102 | 111 | ||
| 103 | if __name__ == "__main__": | 112 | if __name__ == "__main__": |
| 104 | run_tests() | 113 | run_tests() |


修改的是target的yaml,配套用例应该设置target的requires_grad=True