You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2020/01/18 08:01:33 UTC

[GitHub] [incubator-mxnet] eric-haibin-lin opened a new pull request #17372: [BUGFIX] fix model zoo parallel download

eric-haibin-lin opened a new pull request #17372: [BUGFIX] fix model zoo parallel download
URL: https://github.com/apache/incubator-mxnet/pull/17372
 
 
   ## Description ##
   Fixes #17332
   
   ## Checklist ##
   ### Essentials ###
   Please feel free to remove inapplicable items for your PR.
   - [ ] The PR title starts with [MXNET-$JIRA_ID], where $JIRA_ID refers to the relevant [JIRA issue](https://issues.apache.org/jira/projects/MXNET/issues) created (except PRs with tiny changes)
   - [ ] Changes are complete (i.e. I finished coding on this PR)
   - [ ] All changes have test coverage:
   - Unit tests are added for small changes to verify correctness (e.g. adding a new operator)
   - Nightly tests are added for complicated/long-running ones (e.g. changing distributed kvstore)
   - Build tests will be added for build configuration changes (e.g. adding a new build option with NCCL)
   - [ ] Code is well-documented: 
   - For user-facing API changes, API doc string has been updated. 
   - For new C++ functions in header files, their functionalities and arguments are documented. 
   - For new examples, README.md is added to explain the what the example does, the source of the dataset, expected performance on test set and reference to the original paper if applicable
   - Check the API doc at https://mxnet-ci-doc.s3-accelerate.dualstack.amazonaws.com/PR-$PR_ID/$BUILD_ID/index.html
   - [ ] To the best of my knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change
   
   ### Changes ###
   - [ ] Feature1, tests, (and when applicable, API doc)
   - [ ] Feature2, tests, (and when applicable, API doc)
   
   ## Comments ##
   - If this change is a backward incompatible change, why must this change be made.
   - Interesting edge cases to note here
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] eric-haibin-lin commented on a change in pull request #17372: [BUGFIX] fix model zoo parallel download

Posted by GitBox <gi...@apache.org>.
eric-haibin-lin commented on a change in pull request #17372: [BUGFIX] fix model zoo parallel download
URL: https://github.com/apache/incubator-mxnet/pull/17372#discussion_r370283042
 
 

 ##########
 File path: python/mxnet/gluon/model_zoo/model_store.py
 ##########
 @@ -103,16 +105,19 @@ def get_model_file(name, root=os.path.join(base.data_dir(), 'models')):
 
     util.makedirs(root)
 
-    zip_file_path = os.path.join(root, file_name+'.zip')
     repo_url = os.environ.get('MXNET_GLUON_REPO', apache_repo_url)
     if repo_url[-1] != '/':
         repo_url = repo_url + '/'
-    download(_url_format.format(repo_url=repo_url, file_name=file_name),
-             path=zip_file_path,
-             overwrite=True)
-    with zipfile.ZipFile(zip_file_path) as zf:
-        zf.extractall(root)
-    os.remove(zip_file_path)
+
+    with tempfile.NamedTemporaryFile(dir=root) as zip_file:
+        download(_url_format.format(repo_url=repo_url, file_name=file_name),
+                 path=zip_file.name, overwrite=True, inplace=True)
 
 Review comment:
   Thanks for the comment! That makes me think NamedTemporaryFile and TemporaryFile are quite restricted. I have to modify other functions that uses this file so that they operate on the open file object itself. For now I'll fallback to the previous method where the file is explicitly cleaned up. 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] leezu commented on a change in pull request #17372: [BUGFIX] fix model zoo parallel download

Posted by GitBox <gi...@apache.org>.
leezu commented on a change in pull request #17372: [BUGFIX] fix model zoo parallel download
URL: https://github.com/apache/incubator-mxnet/pull/17372#discussion_r370251465
 
 

 ##########
 File path: python/mxnet/gluon/model_zoo/model_store.py
 ##########
 @@ -103,16 +105,19 @@ def get_model_file(name, root=os.path.join(base.data_dir(), 'models')):
 
     util.makedirs(root)
 
-    zip_file_path = os.path.join(root, file_name+'.zip')
     repo_url = os.environ.get('MXNET_GLUON_REPO', apache_repo_url)
     if repo_url[-1] != '/':
         repo_url = repo_url + '/'
-    download(_url_format.format(repo_url=repo_url, file_name=file_name),
-             path=zip_file_path,
-             overwrite=True)
-    with zipfile.ZipFile(zip_file_path) as zf:
-        zf.extractall(root)
-    os.remove(zip_file_path)
+
+    with tempfile.NamedTemporaryFile(dir=root) as zip_file:
+        download(_url_format.format(repo_url=repo_url, file_name=file_name),
+                 path=zip_file.name, overwrite=True, inplace=True)
 
 Review comment:
   From the doc:
   
   >  Whether the name can be used to open the file a second time, while the named temporary file is still open, varies across platforms (it can be so used on Unix; it cannot on Windows NT or later). If delete is true (the default), the file is deleted as soon as it is closed.
   
   Here you are taking the file name of the opened file, passing it to download and therein opening it again. One workaround is to work with the open file object itself when using `tempfile.NamedTemporaryFile`.
   
   Reference https://docs.python.org/2/library/tempfile.html

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] leezu merged pull request #17372: [BUGFIX] fix model zoo parallel download

Posted by GitBox <gi...@apache.org>.
leezu merged pull request #17372: [BUGFIX] fix model zoo parallel download
URL: https://github.com/apache/incubator-mxnet/pull/17372
 
 
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] eric-haibin-lin commented on issue #17372: [BUGFIX] fix model zoo parallel download

Posted by GitBox <gi...@apache.org>.
eric-haibin-lin commented on issue #17372: [BUGFIX] fix model zoo parallel download
URL: https://github.com/apache/incubator-mxnet/pull/17372#issuecomment-577988277
 
 
   @ptrendx can we cherrypick this fix to 1.6?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] leezu commented on a change in pull request #17372: [BUGFIX] fix model zoo parallel download

Posted by GitBox <gi...@apache.org>.
leezu commented on a change in pull request #17372: [BUGFIX] fix model zoo parallel download
URL: https://github.com/apache/incubator-mxnet/pull/17372#discussion_r370251465
 
 

 ##########
 File path: python/mxnet/gluon/model_zoo/model_store.py
 ##########
 @@ -103,16 +105,19 @@ def get_model_file(name, root=os.path.join(base.data_dir(), 'models')):
 
     util.makedirs(root)
 
-    zip_file_path = os.path.join(root, file_name+'.zip')
     repo_url = os.environ.get('MXNET_GLUON_REPO', apache_repo_url)
     if repo_url[-1] != '/':
         repo_url = repo_url + '/'
-    download(_url_format.format(repo_url=repo_url, file_name=file_name),
-             path=zip_file_path,
-             overwrite=True)
-    with zipfile.ZipFile(zip_file_path) as zf:
-        zf.extractall(root)
-    os.remove(zip_file_path)
+
+    with tempfile.NamedTemporaryFile(dir=root) as zip_file:
+        download(_url_format.format(repo_url=repo_url, file_name=file_name),
+                 path=zip_file.name, overwrite=True, inplace=True)
 
 Review comment:
   From the doc:
   
   >  Whether the name can be used to open the file a second time, while the named temporary file is still open, varies across platforms (it can be so used on Unix; it cannot on Windows NT or later). If delete is true (the default), the file is deleted as soon as it is closed.
   
   Here you are taking the file name of the opened file, passing it to download and therein opening it again. You need to work with the open file object itself when using `tempfile.NamedTemporaryFile`.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] eric-haibin-lin commented on issue #17372: [BUGFIX] fix model zoo parallel download

Posted by GitBox <gi...@apache.org>.
eric-haibin-lin commented on issue #17372: [BUGFIX] fix model zoo parallel download
URL: https://github.com/apache/incubator-mxnet/pull/17372#issuecomment-577534987
 
 
   I keep getting permission denied when tempfile is used... http://jenkins.mxnet-ci.amazon-ml.com/blue/organizations/jenkins/mxnet-validation%2Fwindows-cpu/detail/PR-17372/4/pipeline/175 
   
   @leezu @apeforest any idea why? 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] leezu commented on a change in pull request #17372: [BUGFIX] fix model zoo parallel download

Posted by GitBox <gi...@apache.org>.
leezu commented on a change in pull request #17372: [BUGFIX] fix model zoo parallel download
URL: https://github.com/apache/incubator-mxnet/pull/17372#discussion_r370251465
 
 

 ##########
 File path: python/mxnet/gluon/model_zoo/model_store.py
 ##########
 @@ -103,16 +105,19 @@ def get_model_file(name, root=os.path.join(base.data_dir(), 'models')):
 
     util.makedirs(root)
 
-    zip_file_path = os.path.join(root, file_name+'.zip')
     repo_url = os.environ.get('MXNET_GLUON_REPO', apache_repo_url)
     if repo_url[-1] != '/':
         repo_url = repo_url + '/'
-    download(_url_format.format(repo_url=repo_url, file_name=file_name),
-             path=zip_file_path,
-             overwrite=True)
-    with zipfile.ZipFile(zip_file_path) as zf:
-        zf.extractall(root)
-    os.remove(zip_file_path)
+
+    with tempfile.NamedTemporaryFile(dir=root) as zip_file:
+        download(_url_format.format(repo_url=repo_url, file_name=file_name),
+                 path=zip_file.name, overwrite=True, inplace=True)
 
 Review comment:
   From the doc:
   
   >  Whether the name can be used to open the file a second time, while the named temporary file is still open, varies across platforms (it can be so used on Unix; it cannot on Windows NT or later). If delete is true (the default), the file is deleted as soon as it is closed.
   
   Here you are taking the file name of the opened file, passing it to download and therein opening it again. One workaround is to work with the open file object itself when using `tempfile.NamedTemporaryFile`.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] ChaiBapchya commented on a change in pull request #17372: [BUGFIX] fix model zoo parallel download

Posted by GitBox <gi...@apache.org>.
ChaiBapchya commented on a change in pull request #17372: [BUGFIX] fix model zoo parallel download
URL: https://github.com/apache/incubator-mxnet/pull/17372#discussion_r368258140
 
 

 ##########
 File path: python/mxnet/gluon/utils.py
 ##########
 @@ -240,18 +246,25 @@ def _handle_errors(rv, src):
             finally:
                 raise OSError(msg)
 
-    def _replace_atomic(src, dst):
+    def replace_file(src, dst):
         """Implement atomic os.replace with windows.
+
         refer to https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-movefileexw
         The function fails when one of the process(copy, flush, delete) fails.
-        Internal use only"""
+
+        Parameters
+        ----------
+        src : source file path
+        dst : destination file path
+        """
         _handle_errors(ctypes.windll.kernel32.MoveFileExW(
             _str_to_unicode(src), _str_to_unicode(dst),
             _windows_default_flags | _MOVEFILE_REPLACE_EXISTING
         ), src)
 
 
-def download(url, path=None, overwrite=False, sha1_hash=None, retries=5, verify_ssl=True):
+def download(url, path=None, overwrite=False, sha1_hash=None, retries=5, verify_ssl=True,
+             inplace=False):
     """Download an given URL
 
 Review comment:
   nitpick
   ```suggestion
       """Download a given URL
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] leezu commented on a change in pull request #17372: [BUGFIX] fix model zoo parallel download

Posted by GitBox <gi...@apache.org>.
leezu commented on a change in pull request #17372: [BUGFIX] fix model zoo parallel download
URL: https://github.com/apache/incubator-mxnet/pull/17372#discussion_r370284078
 
 

 ##########
 File path: python/mxnet/gluon/model_zoo/model_store.py
 ##########
 @@ -103,16 +105,19 @@ def get_model_file(name, root=os.path.join(base.data_dir(), 'models')):
 
     util.makedirs(root)
 
-    zip_file_path = os.path.join(root, file_name+'.zip')
     repo_url = os.environ.get('MXNET_GLUON_REPO', apache_repo_url)
     if repo_url[-1] != '/':
         repo_url = repo_url + '/'
-    download(_url_format.format(repo_url=repo_url, file_name=file_name),
-             path=zip_file_path,
-             overwrite=True)
-    with zipfile.ZipFile(zip_file_path) as zf:
-        zf.extractall(root)
-    os.remove(zip_file_path)
+
+    with tempfile.NamedTemporaryFile(dir=root) as zip_file:
+        download(_url_format.format(repo_url=repo_url, file_name=file_name),
+                 path=zip_file.name, overwrite=True, inplace=True)
 
 Review comment:
   Yes. You can set `delete=False` and this restriction should go away.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] eric-haibin-lin commented on a change in pull request #17372: [BUGFIX] fix model zoo parallel download

Posted by GitBox <gi...@apache.org>.
eric-haibin-lin commented on a change in pull request #17372: [BUGFIX] fix model zoo parallel download
URL: https://github.com/apache/incubator-mxnet/pull/17372#discussion_r370324247
 
 

 ##########
 File path: python/mxnet/gluon/model_zoo/model_store.py
 ##########
 @@ -103,16 +105,19 @@ def get_model_file(name, root=os.path.join(base.data_dir(), 'models')):
 
     util.makedirs(root)
 
-    zip_file_path = os.path.join(root, file_name+'.zip')
     repo_url = os.environ.get('MXNET_GLUON_REPO', apache_repo_url)
     if repo_url[-1] != '/':
         repo_url = repo_url + '/'
-    download(_url_format.format(repo_url=repo_url, file_name=file_name),
-             path=zip_file_path,
-             overwrite=True)
-    with zipfile.ZipFile(zip_file_path) as zf:
-        zf.extractall(root)
-    os.remove(zip_file_path)
+
+    with tempfile.NamedTemporaryFile(dir=root) as zip_file:
+        download(_url_format.format(repo_url=repo_url, file_name=file_name),
+                 path=zip_file.name, overwrite=True, inplace=True)
 
 Review comment:
   I think @apeforest suggested using `TemporaryFile` because it can be automatically cleaned up. If we need to cleanup ourselves, then there's not much difference using it or not

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services