Explorar o código

copytree implementation for py37 compatibility (#162)

* copytree implementation for py37 compatibility

* Running tests for python3.7

* Increment version

* Python3.7 notions
Alexey Bukhtiyarov %!s(int64=4) %!d(string=hai) anos
pai
achega
e58eb430b1
Modificáronse 6 ficheiros con 38 adicións e 5 borrados
  1. 20 0
      .circleci/config.yml
  2. 1 1
      README.md
  3. 1 1
      docs/user/quickstart.md
  4. 1 1
      hivemind/__init__.py
  5. 14 2
      hivemind/server/checkpoints.py
  6. 1 0
      setup.py

+ 20 - 0
.circleci/config.yml

@@ -1,6 +1,26 @@
 version: 2.1
 version: 2.1
 
 
 jobs:
 jobs:
+  build-and-test-py37:
+    docker:
+      - image: circleci/python:3.7.10
+    steps:
+      - checkout
+      - restore_cache:
+          keys:
+            - v1-{{ checksum "requirements.txt" }}-{{ checksum "requirements-dev.txt" }}
+      - run: pip install -r requirements.txt
+      - run: pip install -r requirements-dev.txt
+      - save_cache:
+          key: v1-{{ checksum "requirements.txt" }}-{{ checksum "requirements-dev.txt" }}
+          paths:
+            - '~/.cache/pip'
+      - run:
+          command: pip install -e .
+          name: setup
+      - run:
+          command: pytest ./tests
+          name: tests
   build-and-test-py38:
   build-and-test-py38:
     docker:
     docker:
       - image: circleci/python:3.8.1
       - image: circleci/python:3.8.1

+ 1 - 1
README.md

@@ -24,7 +24,7 @@ the [NeurIPS 2020 paper](https://arxiv.org/abs/2002.04013).
 
 
 ## Installation
 ## Installation
 
 
-Before installing hivemind, make sure that your environment has Python 3.8+
+Before installing hivemind, make sure that your environment has Python 3.7+
 and [PyTorch](https://pytorch.org/get-started/locally/#start-locally) with a version at least as new as 1.6.0.
 and [PyTorch](https://pytorch.org/get-started/locally/#start-locally) with a version at least as new as 1.6.0.
 
 
 To start using this library, you can either use the pip package manager or build it from source. Since currently the
 To start using this library, you can either use the pip package manager or build it from source. Since currently the

+ 1 - 1
docs/user/quickstart.md

@@ -16,7 +16,7 @@ pip install .
 
 
 You can also install it in the editable mode with `pip install -e .`.
 You can also install it in the editable mode with `pip install -e .`.
 
 
-* __Dependencies:__ Hivemind requires Python 3.8+.
+* __Dependencies:__ Hivemind requires Python 3.7+.
   The [requirements](https://github.com/learning-at-home/hivemind/blob/master/requirements.txt) are installed
   The [requirements](https://github.com/learning-at-home/hivemind/blob/master/requirements.txt) are installed
   automatically.
   automatically.
 * __OS support:__ Linux and macOS should just work. We do not officially support Windows, but you are welcome to
 * __OS support:__ Linux and macOS should just work. We do not officially support Windows, but you are welcome to

+ 1 - 1
hivemind/__init__.py

@@ -3,4 +3,4 @@ from hivemind.dht import *
 from hivemind.server import *
 from hivemind.server import *
 from hivemind.utils import *
 from hivemind.utils import *
 
 
-__version__ = '0.9.0'
+__version__ = '0.9.1'

+ 14 - 2
hivemind/server/checkpoints.py

@@ -1,7 +1,7 @@
 import threading
 import threading
 from datetime import datetime
 from datetime import datetime
 from pathlib import Path
 from pathlib import Path
-from shutil import copytree
+from shutil import copy2
 from tempfile import TemporaryDirectory
 from tempfile import TemporaryDirectory
 from typing import Dict
 from typing import Dict
 import os
 import os
@@ -18,6 +18,18 @@ def dir_is_correct(directory: Path):
     return True
     return True
 
 
 
 
+def copy_tree(src: str, dst: str):
+    if not os.path.exists(dst):
+        os.makedirs(dst)
+    for item in os.listdir(src):
+        src_entry = os.path.join(src, item)
+        dst_entry = os.path.join(dst, item)
+        if os.path.isdir(src_entry):
+            copy_tree(src_entry, dst_entry)
+        else:
+            copy2(src_entry, dst_entry)
+
+
 class CheckpointSaver(threading.Thread):
 class CheckpointSaver(threading.Thread):
     def __init__(self, expert_backends: Dict[str, ExpertBackend], checkpoint_dir: Path, update_period: int):
     def __init__(self, expert_backends: Dict[str, ExpertBackend], checkpoint_dir: Path, update_period: int):
         super().__init__()
         super().__init__()
@@ -45,7 +57,7 @@ def store_experts(experts: Dict[str, ExpertBackend], checkpoint_dir: Path):
             checkpoint_name = expert_dir / f'checkpoint_{timestamp}.pt'
             checkpoint_name = expert_dir / f'checkpoint_{timestamp}.pt'
             torch.save(expert_backend.state_dict(), checkpoint_name)
             torch.save(expert_backend.state_dict(), checkpoint_name)
             os.symlink(checkpoint_name, expert_dir / 'checkpoint_last.pt')
             os.symlink(checkpoint_name, expert_dir / 'checkpoint_last.pt')
-        copytree(tmpdirname, str(checkpoint_dir), dirs_exist_ok=True)
+        copy_tree(tmpdirname, str(checkpoint_dir))
 
 
 
 
 def load_weights(experts: Dict[str, ExpertBackend], checkpoint_dir: Path):
 def load_weights(experts: Dict[str, ExpertBackend], checkpoint_dir: Path):

+ 1 - 0
setup.py

@@ -83,6 +83,7 @@ setup(
         'Intended Audience :: Science/Research',
         'Intended Audience :: Science/Research',
         'License :: OSI Approved :: MIT License',
         'License :: OSI Approved :: MIT License',
         'Programming Language :: Python :: 3',
         'Programming Language :: Python :: 3',
+        'Programming Language :: Python :: 3.7',
         'Programming Language :: Python :: 3.8',
         'Programming Language :: Python :: 3.8',
         'Programming Language :: Python :: 3.9',
         'Programming Language :: Python :: 3.9',
         'Topic :: Scientific/Engineering',
         'Topic :: Scientific/Engineering',