Skip to content

Commit 3f85596

Browse files
authored
fix c class ut (#2069)
1 parent 5cc6c05 commit 3f85596

18 files changed

Lines changed: 476 additions & 60 deletions

mindnlp/core/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
from .amp import autocast, GradScaler
4848

4949
from . import profiler, cuda, optim, amp, compiler, jit, version, __future__, overrides, \
50-
return_types, linalg, fx, backends, testing, nn, fft
50+
return_types, linalg, fx, backends, testing, nn, fft, _jit_internal, utils
5151

5252
from ._lowrank import svd_lowrank
5353
from .random import get_rng_state, initial_seed, manual_seed, seed, set_rng_state

mindnlp/core/_dynamo/utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
def is_compile_supported(device_type):
2+
return False
3+

mindnlp/core/_jit_internal.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
from typing import ( # noqa: UP035, F401 # (Dict, List, Tuple) imported by torch.jit.annotations
2+
Any,
3+
Callable,
4+
Dict,
5+
Final,
6+
ForwardRef,
7+
get_args,
8+
get_origin,
9+
List,
10+
Optional,
11+
Tuple,
12+
TypeVar,
13+
Union,
14+
)
15+
116
class FunctionModifiers:
217
"""
318
Used to denote the behavior of a function in TorchScript. See export() and

mindnlp/core/_tensor.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,11 @@ def clamp_min(self, value):
463463
Tensor.unsqueeze_ = ops.inplace_unsqueeze
464464
StubTensor.unsqueeze_ = ops.inplace_unsqueeze
465465

466+
def pin_memory(self, *args, **kwargs):
467+
return self
468+
469+
Tensor.pin_memory = pin_memory
470+
StubTensor.pin_memory = pin_memory
466471

467472
def _rebuild_from_type_v2(func, new_type, args, state):
468473
ret = func(*args)

mindnlp/core/jit/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# _overload,
1010
# _overload_method,
1111
# export,
12-
# Final,
12+
Final,
1313
# Future,
1414
# ignore,
1515
# is_scripting,

mindnlp/core/jit/annotations.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from core._jit_internal import ( # type: ignore[attr-defined]
1+
from .._jit_internal import ( # type: ignore[attr-defined]
22
# _Await,
33
# _qualified_name,
44
# Any,
@@ -15,7 +15,7 @@
1515
# is_optional,
1616
# is_tuple,
1717
# is_union,
18-
# List,
18+
List,
1919
# Optional,
2020
# Tuple,
2121
# Union,

mindnlp/core/linalg/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from collections import namedtuple
2-
from mindspore import ops
2+
from mindspore import ops, mint
33
from mindspore.ops._primitive_cache import _get_cache_prim
44

55
from mindnlp import core
@@ -21,3 +21,5 @@ def cholesky_ex(A, *, upper=False, check_errors=False, out=None):
2121
return linalg_cholesky_ex(out, info)
2222

2323

24+
def norm(A, ord=None, dim=None, keepdim=False, *, out=None, dtype=None):
25+
return mint.norm(A, ord, dim, keepdim, dtype=dtype)

mindnlp/core/nn/functional.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ def avg_pool2d(input, kernel_size, stride=None, padding=0, ceil_mode=False, coun
162162

163163
return ops.avg_pool2d(input, kernel_size, stride, padding, ceil_mode, count_include_pad, divisor_override)
164164

165+
def adaptive_avg_pool1d(input, output_size):
166+
if use_pyboost():
167+
return mint.nn.functional.adaptive_avg_pool1d(input, output_size)
168+
return ops.adaptive_avg_pool1d(input, output_size)
169+
165170
def adaptive_avg_pool2d(input, output_size):
166171
if use_pyboost():
167172
return mint.nn.functional.adaptive_avg_pool2d(input, output_size)
@@ -1206,7 +1211,7 @@ def _none_or_dtype(input: Optional[core.Tensor]) -> Optional[int]:
12061211
raise RuntimeError("input to _none_or_dtype() must be None or core.Tensor")
12071212

12081213
def unfold(input, kernel_size, dilation=1, padding=0, stride=1):
1209-
if use_pyboost():
1214+
if use_pyboost() and not ON_A1:
12101215
return mint.nn.functional.unfold(input, kernel_size, dilation, padding, stride)
12111216
return ops.unfold(input, kernel_size, dilation, padding, stride)
12121217

mindnlp/core/nn/modules/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from .activation import *
99
from .conv import Conv3d, Conv2d, Conv1d, ConvTranspose2d, ConvTranspose1d
1010
from .padding import ZeroPad2d, ConstantPad2d, ConstantPad1d, ConstantPad3d
11-
from .batchnorm import BatchNorm2d, BatchNorm1d
11+
from .batchnorm import BatchNorm2d, BatchNorm1d, SyncBatchNorm
1212
from .pooling import AdaptiveAvgPool2d, AvgPool1d, MaxPool2d, MaxPool1d, AdaptiveAvgPool1d, AvgPool2d
1313
from .flatten import Unflatten, Flatten
1414
from .rnn_cell import RNNCell, GRUCell, LSTMCell

0 commit comments

Comments
 (0)