From 32a16ef2f5261bbaa4d5d0e22631608c4a6aa5ad Mon Sep 17 00:00:00 2001 From: lvyufeng Date: Sun, 21 Sep 2025 15:40:36 +0000 Subject: [PATCH] fix u-w class on GPU --- mindtorch/_apis/cpu.py | 5 +++-- mindtorch/_apis/gpu.py | 13 ++++++++----- mindtorch/nn/functional.py | 3 +++ mindtorch/ops/array.py | 2 +- mindtorch/ops/other.py | 3 +++ 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/mindtorch/_apis/cpu.py b/mindtorch/_apis/cpu.py index 85dc5e6d8..12fdda459 100644 --- a/mindtorch/_apis/cpu.py +++ b/mindtorch/_apis/cpu.py @@ -1089,7 +1089,7 @@ def leaky_relu(input, negative_slope): select_op = maximum if negative_slope > 1: select_op = minimum - return select_op(mul(negative_slope, input), input) + return select_op(mul(input, negative_slope), input) def ceil(input): return legacy.ceil(input) @@ -1220,7 +1220,8 @@ def logsumexp(input, dim, keepdim=False): return add(input_logsumexp, input_max) def bernoulli(input, generator): - return legacy.bernoulli(input, seed, offset) + seed, offset = generator._step(12) # pylint: disable=protected-access + return legacy.bernoulli(input, 0.5, seed.item(), offset.item()) def right_shift(input, other): return legacy.right_shift(input, other) diff --git a/mindtorch/_apis/gpu.py b/mindtorch/_apis/gpu.py index 5affa4ca7..b59c8db14 100644 --- a/mindtorch/_apis/gpu.py +++ b/mindtorch/_apis/gpu.py @@ -746,9 +746,9 @@ def conv_transpose2d(input, weight, bias=None, stride=1, padding=0, output_paddi pad_mode = 'pad' pad = padding if isinstance(padding, tuple): - pad = (0, 0, padding[0], padding[0]) + pad = (padding[0], padding[0], padding[1], padding[1]) elif isinstance(padding, int): - pad = (0, 0) + (padding,) * 2 + pad = (padding,) * 4 if not isinstance(padding, (int, tuple)): pad_mode = padding pad = (0,) * 4 @@ -758,7 +758,6 @@ def conv_transpose2d(input, weight, bias=None, stride=1, padding=0, output_paddi in_channel, out_channels = weight.shape[0], weight.shape[1] * groups kernel_size = weight.shape[2:] - n, _, h, w = input.shape h_add = _deconv_output_length(pad_mode, kernel_size[0], stride[0], dilation[0], pad[0] + pad[1]) w_add = _deconv_output_length(pad_mode, kernel_size[1], stride[1], dilation[1], pad[2] + pad[3]) @@ -1004,7 +1003,7 @@ def leaky_relu(input, negative_slope): select_op = maximum if negative_slope > 1: select_op = minimum - return select_op(mul(negative_slope, input), input) + return select_op(mul(input, negative_slope), input) def ceil(input): return legacy.ceil(input) @@ -1146,4 +1145,8 @@ def search_sorted(sorted_sequence, values, sorter, dtype, right): return legacy.search_sorted(sorted_sequence, values, sorter, dtype, right) def einsum(equation, operands): - return legacy.einsum(operands, equation) \ No newline at end of file + return legacy.einsum(operands, equation) + +def unique2(input, sorted, return_inverse, return_counts): + outs = legacy.unique(input) + return outs + (None,) diff --git a/mindtorch/nn/functional.py b/mindtorch/nn/functional.py index 49dcac19d..ba128fd8a 100644 --- a/mindtorch/nn/functional.py +++ b/mindtorch/nn/functional.py @@ -47,6 +47,9 @@ def elu(input, alpha=1.0): return execute('elu', input, alpha) def glu(input, dim=-1): + if input.device.type == 'cuda': + x, y = input.chunk(2, dim) + return x * sigmoid(y) return execute('glu', input, dim) def softplus(input, beta=1, threshold=20): diff --git a/mindtorch/ops/array.py b/mindtorch/ops/array.py index 75fcd51de..fd2edd247 100644 --- a/mindtorch/ops/array.py +++ b/mindtorch/ops/array.py @@ -908,7 +908,7 @@ def range_(start, length): stacked_indices = indices[0] stacked_indices = stacked_indices.to(mindtorch.int32) stacked_indices = where( - stacked_indices < 0, stacked_indices + mindtorch.tensor(dim_sizes, device=stacked_indices.device), stacked_indices + stacked_indices < 0, stacked_indices + mindtorch.tensor(dim_sizes, dtype=stacked_indices.dtype, device=stacked_indices.device), stacked_indices ) axis = dims[0] if len(dims) > 1: diff --git a/mindtorch/ops/other.py b/mindtorch/ops/other.py index f2098d395..a0a119bb7 100644 --- a/mindtorch/ops/other.py +++ b/mindtorch/ops/other.py @@ -27,6 +27,9 @@ def broadcast_tensors(*tensors): # broadcast_to def broadcast_to(input, shape): + if input.shape == shape: + return input + new_shape = () for s in shape: if not isinstance(s, int):