Skip to content

Commit

Permalink
Fix tqdm in downloader (#4603)
Browse files Browse the repository at this point in the history
* fix tqdm

* rtol -> atol
  • Loading branch information
sijunhe committed Feb 1, 2023
1 parent a600b41 commit 19f7623
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 30 deletions.
27 changes: 1 addition & 26 deletions paddlenlp/utils/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import os
import os.path as osp
import shutil
import sys
import tarfile
import threading
import time
Expand All @@ -28,34 +27,10 @@
import requests
from huggingface_hub import get_hf_file_metadata, hf_hub_url
from huggingface_hub.utils import EntryNotFoundError
from tqdm.auto import tqdm

from .env import DOWNLOAD_SERVER, FAILED_STATUS, SUCCESS_STATUS
from .file_lock import FileLock

try:
from tqdm import tqdm
except: # noqa: E722

class tqdm(object):
def __init__(self, total=None, **kwargs):
self.total = total
self.n = 0

def update(self, n):
self.n += n
if self.total is None:
sys.stderr.write("\r{0:.1f} bytes".format(self.n))
else:
sys.stderr.write("\r{0:.1f}%".format(100 * self.n / float(self.total)))
sys.stderr.flush()

def __enter__(self):
return self

def __exit__(self, exc_type, exc_val, exc_tb):
sys.stderr.write("\n")


from .log import logger

__all__ = ["get_weights_path_from_url"]
Expand Down
2 changes: 1 addition & 1 deletion tests/transformers/bert/test_modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ def test_bert_classes_from_local_dir(self, class_name, pytorch_class_name: str |
np.allclose(
paddle_logit.detach().cpu().reshape([-1])[:9].numpy(),
torch_logit.detach().cpu().reshape([-1])[:9].numpy(),
rtol=1e-4,
atol=1e-3,
)
)

Expand Down
2 changes: 1 addition & 1 deletion tests/transformers/gpt/test_modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ def test_gpt_classes_from_local_dir(self, paddle_class_name, pytorch_class_name:
np.allclose(
paddle_logit.detach().cpu().numpy().reshape([-1])[:9],
torch_logit.detach().cpu().numpy().reshape([-1])[:9],
rtol=1e-3,
atol=1e-3,
)
)

Expand Down
2 changes: 1 addition & 1 deletion tests/transformers/roberta/test_modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ def test_roberta_classes_from_local_dir(self, class_name):
np.allclose(
paddle_logit.detach().cpu().reshape([-1])[:9].numpy(),
torch_logit.detach().cpu().reshape([-1])[:9].numpy(),
rtol=1e-4,
atol=1e-3,
)
)

Expand Down
2 changes: 1 addition & 1 deletion tests/transformers/t5/test_modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ def test_t5_for_conditional_generation(self):
np.allclose(
paddle_logit.detach().cpu().reshape([-1])[:9].numpy(),
torch_logit.detach().cpu().reshape([-1])[:9].numpy(),
rtol=1e-4,
atol=1e-3,
)
)

Expand Down

0 comments on commit 19f7623

Please sign in to comment.