Skip to content

Commit a5cfaaf

Browse files
authored
init mimm & move tests folder (#1804)
1 parent 6a2b4f1 commit a5cfaaf

File tree

875 files changed

+10657
-1388
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

875 files changed

+10657
-1388
lines changed

.github/pylint.conf

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,12 @@ disable=raw-checker-failed,
211211
pointless-string-statement,
212212
redundant-keyword-arg,
213213
too-many-function-args,
214-
assignment-from-none
214+
assignment-from-none,
215+
use-dict-literal,
216+
consider-using-generator,
217+
fixme,
218+
use-a-generator,
219+
nested-min-max
215220

216221
# Enable the message, report, category or checker with the given id(s). You can
217222
# either give multiple identifier separated by comma (,) or put this option

.github/workflows/ci_pipeline.yaml

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ on:
88
branches: [ "master" ]
99
paths:
1010
- 'mindnlp/**'
11-
- 'tests/ut/**'
11+
- 'tests/**'
1212
- '!mindnlp/dataset/**'
13-
- '!tests/ut/dataset/**'
13+
- '!tests/dataset/**'
1414
- '!docs/**'
1515
- '.github/workflows/**'
1616
push:
@@ -80,7 +80,7 @@ jobs:
8080
pip install -r download.txt
8181
- name: Test with pytest
8282
run: |
83-
pytest -c pytest.ini -m 'not download and not gpu_only' --ignore=tests/ut/transformers tests/ut
83+
pytest -c pytest.ini -m 'not download and not gpu_only' --ignore=tests/transformers tests/ut
8484
8585
release-test:
8686
needs: pylint-check
@@ -104,7 +104,7 @@ jobs:
104104
pip install https://ms-release.obs.cn-north-4.myhuaweicloud.com/${{matrix.ms_version}}/MindSpore/unified/x86_64/mindspore-${{matrix.ms_version}}-cp39-cp39-linux_x86_64.whl --trusted-host ms-release.obs.cn-north-4.myhuaweicloud.com
105105
- name: Test with pytest
106106
run: |
107-
pytest -c pytest.ini -m 'not download and not gpu_only' --ignore=tests/ut/transformers tests/ut
107+
pytest -c pytest.ini -m 'not download and not gpu_only' --ignore=tests/transformers tests/ut
108108
# pytest -c pytest.ini -m 'not download and not gpu_only' tests/ut
109109
110110
transformers-model-test:
@@ -133,36 +133,7 @@ jobs:
133133
pip install -r download.txt
134134
- name: Test with pytest
135135
run: |
136-
pytest -vs tests/ut/transformers/models/${{ matrix.alpha }}*/test_modeling*
137-
138-
st-test:
139-
needs: ut-test
140-
strategy:
141-
matrix:
142-
os: [ubuntu-latest, macos-latest]
143-
python: [3.9]
144-
runs-on: ${{ matrix.os }}
145-
steps:
146-
- uses: actions/checkout@v3
147-
- name: Set up Python
148-
uses: actions/setup-python@v4
149-
with:
150-
python-version: ${{ matrix.python }}
151-
- name: Install dependencies
152-
run: |
153-
python -m pip install --upgrade pip==24.0
154-
pip install -r requirements/requirements.txt
155-
- name: Install MindSpore
156-
shell: bash
157-
env:
158-
OS: ${{ matrix.os }}
159-
PYTHON: ${{ matrix.python }}
160-
run: |
161-
python .github/install_mindspore.py
162-
pip install -r download.txt
163-
- name: Test ST with pytest
164-
run: |
165-
pytest -c pytest.ini tests/st
136+
pytest -vs tests/transformers/models/${{ matrix.alpha }}*/test_modeling*
166137
167138
kaggle-gpu-test:
168139
needs: pylint-check

mindnlp/common/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"""
2+
common modules for all submodule(transformers, mimm, peft, trl, diffusers, etc), include:
3+
activations, optimization, etc.
4+
"""

mindnlp/transformers/activations.py renamed to mindnlp/common/activations.py

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,51 @@
1717
from collections import OrderedDict
1818
from mindspore import Tensor
1919
from mindnlp.core import nn, ops
20+
from mindnlp.core.nn import functional as F
2021

22+
def gelu_tanh(x: Tensor, inplace: bool = False) -> Tensor:
23+
return F.gelu(x, approximate='tanh')
2124

22-
class QuickGELUActivation(nn.Module):
25+
def quick_gelu(x: Tensor, inplace: bool = False) -> Tensor:
26+
return x * ops.sigmoid(1.702 * x)
27+
28+
def hard_mish(x, inplace: bool = False):
29+
""" Hard Mish
30+
Experimental, based on notes by Mish author Diganta Misra at
31+
https://github.com/digantamisra98/H-Mish/blob/0da20d4bc58e696b6803f2523c58d3c8a82782d0/README.md
32+
"""
33+
if inplace:
34+
return x.mul(0.5 * (x + 2).clamp(min=0, max=2))
35+
else:
36+
return 0.5 * x * (x + 2).clamp(min=0, max=2)
37+
38+
39+
class HardMish(nn.Module):
40+
def __init__(self, inplace: bool = False):
41+
super(HardMish, self).__init__()
42+
self.inplace = inplace
43+
44+
def forward(self, x):
45+
return hard_mish(x, self.inplace)
46+
47+
class GELUTanh(nn.Module):
48+
"""Applies the Gaussian Error Linear Units function (w/ dummy inplace arg)
49+
"""
50+
def __init__(self, inplace: bool = False):
51+
super(GELUTanh, self).__init__()
52+
53+
def forward(self, input: Tensor) -> Tensor:
54+
return F.gelu(input, approximate='tanh')
55+
56+
class QuickGELU(nn.Module):
2357
"""
2458
Applies GELU approximation that is fast but somewhat inaccurate. See: https://github.com/hendrycks/GELUs
2559
"""
2660
def forward(self, input: Tensor) -> Tensor:
2761
r"""
2862
forwards the QuickGELU activation function.
29-
30-
Args:
31-
self (QuickGELUActivation): The instance of the QuickGELUActivation class.
32-
input (Tensor): The input tensor to apply the QuickGELU activation to.
33-
34-
Returns:
35-
Tensor: The tensor resulting from applying the QuickGELU activation to the input tensor.
36-
37-
Raises:
38-
None
3963
"""
40-
return input * ops.sigmoid(1.702 * input)
64+
return quick_gelu(input)
4165

4266

4367
class ClippedGELUActivation(nn.Module):
@@ -288,7 +312,7 @@ def __getitem__(self, key):
288312
"gelu_python": nn.GELU,
289313
"linear": nn.ReLU,
290314
"mish": nn.Mish,
291-
"quick_gelu": QuickGELUActivation,
315+
"quick_gelu": QuickGELU,
292316
"relu": nn.ReLU,
293317
"relu2": ReLUSquaredActivation,
294318
"relu6": nn.ReLU6,
@@ -313,7 +337,6 @@ def get_activation(activation_string):
313337
gelu_new = get_activation("gelu_new")
314338
gelu = get_activation("gelu")
315339
gelu_fast = get_activation("gelu_fast")
316-
quick_gelu = get_activation("quick_gelu")
317340
silu = get_activation("silu")
318341
mish = get_activation("mish")
319342
linear_act = get_activation("linear")
File renamed without changes.

0 commit comments

Comments
 (0)