Skip to content

Commit 58cea12

Browse files
authored
fix pytest error (#1885)
1 parent 46eaebe commit 58cea12

File tree

7 files changed

+40
-37
lines changed

7 files changed

+40
-37
lines changed

.github/workflows/ci_pipeline.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
- name: Set up Python
3232
uses: actions/setup-python@v4
3333
with:
34-
python-version: 3.9
34+
python-version: 3.11
3535
- name: Install dependencies
3636
run: |
3737
python -m pip install --upgrade pip==24.0
@@ -40,7 +40,7 @@ jobs:
4040
shell: bash
4141
env:
4242
OS: ubuntu-latest
43-
PYTHON: 3.9
43+
PYTHON: 3.11
4444
run: |
4545
python .github/install_mindspore.py
4646
pip install -r download.txt
@@ -54,7 +54,7 @@ jobs:
5454
strategy:
5555
matrix:
5656
os: [ubuntu-latest, macos-latest, windows-latest]
57-
python: [3.9]
57+
python: [3.11]
5858
runs-on: ${{ matrix.os }}
5959
steps:
6060
- uses: actions/checkout@v3
@@ -118,7 +118,7 @@ jobs:
118118
- name: Set up Python
119119
uses: actions/setup-python@v4
120120
with:
121-
python-version: 3.9
121+
python-version: 3.11
122122
- name: Install dependencies
123123
run: |
124124
python -m pip install --upgrade pip==24.0
@@ -127,7 +127,7 @@ jobs:
127127
shell: bash
128128
env:
129129
OS: ubuntu-latest
130-
PYTHON: 3.9
130+
PYTHON: 3.11
131131
run: |
132132
python .github/install_mindspore.py
133133
pip install -r download.txt
@@ -141,10 +141,10 @@ jobs:
141141
if: github.event_name == 'push' && github.repository_owner == 'mindspore-lab'
142142
steps:
143143
- uses: actions/checkout@v3
144-
- name: Set up Python 3.9
144+
- name: Set up Python 3.11
145145
uses: actions/setup-python@v4
146146
with:
147-
python-version: 3.9
147+
python-version: 3.11
148148
- uses: "lvyufeng/action-kaggle-gpu-test@latest"
149149
with:
150150
kaggle_username: "${{ secrets.KAGGLE_USERNAME }}"

.github/workflows/doc_rst_check.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- name: Set up Python
1818
uses: actions/setup-python@v4
1919
with:
20-
python-version: 3.9
20+
python-version: 3.11
2121
- name: Install dependencies
2222
run: |
2323
python -m pip install --upgrade pip==24.0

mindnlp/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343
if SOC in ('ascend910', 'ascend310b'):
4444
context.set_context(ascend_config={"precision_mode": "allow_mix_precision"})
4545

46+
if version.parse(mindspore.__version__) < version.parse('2.3.0'):
47+
mindspore.mint = None
48+
4649
from mindspore import jit as ms_jit
4750
from mindnlp import patch
4851
from mindnlp import transformers

mindnlp/sentence/sentence_transformer.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,20 @@
4343
class SentenceTransformer(nn.Sequential):
4444
def __init__(
4545
self,
46-
model_name_or_path: str | None = None,
47-
modules: Iterable[nn.Module] | None = None,
48-
prompts: dict[str, str] | None = None,
49-
default_prompt_name: str | None = None,
50-
similarity_fn_name: str | SimilarityFunction | None = None,
51-
cache_folder: str | None = None,
46+
model_name_or_path: str = None,
47+
modules: Iterable[nn.Module] = None,
48+
prompts: dict[str, str] = None,
49+
default_prompt_name: str = None,
50+
similarity_fn_name: str | SimilarityFunction = None,
51+
cache_folder: str = None,
5252
trust_remote_code: bool = False,
53-
revision: str | None = None,
53+
revision: str = None,
5454
local_files_only: bool = False,
55-
token: bool | str | None = None,
56-
truncate_dim: int | None = None,
57-
model_kwargs: dict[str, Any] | None = None,
58-
tokenizer_kwargs: dict[str, Any] | None = None,
59-
config_kwargs: dict[str, Any] | None = None,
55+
token: bool | str = None,
56+
truncate_dim: int = None,
57+
model_kwargs: dict[str, Any] = None,
58+
tokenizer_kwargs: dict[str, Any] = None,
59+
config_kwargs: dict[str, Any] = None,
6060
):
6161
self.prompts = prompts or {}
6262
self.default_prompt_name = default_prompt_name
@@ -193,8 +193,8 @@ def _load_module_class_from_ref(
193193
class_ref: str,
194194
model_name_or_path: str,
195195
trust_remote_code: bool,
196-
revision: str | None,
197-
model_kwargs: dict[str, Any] | None,
196+
revision: str,
197+
model_kwargs: dict[str, Any],
198198
) -> nn.Module:
199199
# If the class is from sentence_transformers, we can directly import it,
200200
# otherwise, we try to import it dynamically, and if that fails, we fall back to the default import
@@ -206,14 +206,14 @@ def _load_module_class_from_ref(
206206
def _load_sbert_model(
207207
self,
208208
model_name_or_path: str,
209-
token: bool | str | None,
210-
cache_folder: str | None,
211-
revision: str | None = None,
209+
token: bool | str,
210+
cache_folder: str,
211+
revision: str = None,
212212
trust_remote_code: bool = False,
213213
local_files_only: bool = False,
214-
model_kwargs: dict[str, Any] | None = None,
215-
tokenizer_kwargs: dict[str, Any] | None = None,
216-
config_kwargs: dict[str, Any] | None = None,
214+
model_kwargs: dict[str, Any] = None,
215+
tokenizer_kwargs: dict[str, Any] = None,
216+
config_kwargs: dict[str, Any] = None,
217217
) -> dict[str, nn.Module]:
218218
"""
219219
Loads a full SentenceTransformer model using the modules.json file.
@@ -385,14 +385,14 @@ def _load_sbert_model(
385385
def _load_auto_model(
386386
self,
387387
model_name_or_path: str,
388-
token: bool | str | None,
389-
cache_folder: str | None,
390-
revision: str | None = None,
388+
token: bool | str,
389+
cache_folder: str,
390+
revision: str = None,
391391
trust_remote_code: bool = False,
392392
local_files_only: bool = False,
393-
model_kwargs: dict[str, Any] | None = None,
394-
tokenizer_kwargs: dict[str, Any] | None = None,
395-
config_kwargs: dict[str, Any] | None = None,
393+
model_kwargs: dict[str, Any] = None,
394+
tokenizer_kwargs: dict[str, Any] = None,
395+
config_kwargs: dict[str, Any] = None,
396396
) -> list[nn.Module]:
397397
"""
398398
Creates a simple Transformer + Mean Pooling model and returns the modules

tests/core/modules/loss/test_cmrc2018loss.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import mindspore
2020
from ddt import ddt, data
2121
from mindspore import Tensor
22-
from mindnlp.core.modules import CMRC2018Loss
22+
from mindnlp.common.modules import CMRC2018Loss
2323
from ....common import MindNLPTestCase
2424

2525
@ddt

tests/core/modules/loss/test_rdrop_loss.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import mindspore
2121
from ddt import ddt, data
2222
from mindspore import Tensor
23-
from mindnlp.core.modules import RDropLoss
23+
from mindnlp.common.modules import RDropLoss
2424
from ....common import MindNLPTestCase
2525

2626
@ddt

tests/core/modules/test_crf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import mindspore
2424
from mindnlp.core import nn, ops
2525

26-
from mindnlp.core.modules import CRF
26+
from mindnlp.common.modules import CRF
2727

2828
RANDOM_SEED = 1478754
2929

0 commit comments

Comments
 (0)