Skip to content

threads_exclusive_http_get fix #2005

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/ci_pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,7 @@ jobs:
OS: ubuntu-latest
PYTHON: 3.11
run: |
python .github/install_mindspore.py
pip install -r download.txt
pip install mindspore
- name: Test with pytest
run: |
pytest -vs tests/transformers/models/${{ matrix.alpha }}*/test_modeling*
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/make_wheel_releases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
run: python -m build --wheel

- name: Upload file
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: mindnlp-whl
path: dist/*
Expand Down
2 changes: 1 addition & 1 deletion mindnlp/core/ops/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def narrow(input, dim, start, length):
has_nonzero = hasattr(mindspore.mint, 'nonzero')
def nonzero(input, *, as_tuple=False):
if use_pyboost() and has_nonzero:
return mindspore.mint.nonzero(input, as_tuple)
return mindspore.mint.nonzero(input, as_tuple=as_tuple)
_nonzero = _get_cache_prim(ops.NonZero)()
out = _nonzero(input)
if as_tuple:
Expand Down
7 changes: 6 additions & 1 deletion mindnlp/utils/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def threads_exclusive_http_get(url, storage_folder=None, md5sum=None, download_f
if sys.platform != "win32":
import fcntl # pylint: disable=import-error
else:
import winfcntlock as fcntl # pylint: disable=import-error
from . import winfcntlock as fcntl # pylint: disable=import-error
with open(lock_file_path, 'w') as lock_file:
fd = lock_file.fileno()
try:
Expand All @@ -160,6 +160,11 @@ def threads_exclusive_http_get(url, storage_folder=None, md5sum=None, download_f
raise exp
finally:
fcntl.flock(fd, fcntl.LOCK_UN)
lock_file.close()
try:
os.remove(lock_file_path)
except Exception as delete_exp:
logging.error(f"Failed to delete lock file: {delete_exp}")


def http_get(url, path=None, md5sum=None, download_file_name=None, proxies=None, headers=None):
Expand Down
7 changes: 4 additions & 3 deletions mindnlp/utils/winfcntlock.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@
LOCK_EX = win32con.LOCKFILE_EXCLUSIVE_LOCK
LOCK_SH = 0 # The default value
LOCK_NB = win32con.LOCKFILE_FAIL_IMMEDIATELY
LOCK_UN = 0x08
__overlapped = pywintypes.OVERLAPPED()

def lock(file, flags):
hfile = win32file._get_osfhandle(file.fileno())
def flock(file, flags):
hfile = win32file._get_osfhandle(file)
win32file.LockFileEx(hfile, flags, 0, 0xffff0000, __overlapped)

def unlock(file):
hfile = win32file._get_osfhandle(file.fileno())
hfile = win32file._get_osfhandle(file)
win32file.UnlockFileEx(hfile, 0, 0xffff0000, __overlapped)