guberti commented on code in PR #11782:
URL: https://github.com/apache/tvm/pull/11782#discussion_r904431759
##########
python/tvm/testing/utils.py:
##########
@@ -1613,6 +1615,47 @@ def is_ampere_or_newer():
return major >= 8
+def fetch_model_from_url(
+ url: str,
+ model_format: str,
+ sha256: str,
+) -> Tuple[tvm.ir.module.IRModule, dict]:
+ """Testing function to fetch a model from a URL and return it as a Relay
+ model. Downloaded files are cached for future re-use.
+
+ Parameters
+ ----------
+ url : str
+ The URL or list of URLs to try downloading the model from.
+
+ model_format: str
+ The file extension of the model format used.
+
+ sha256 : str
+ The sha256 hex hash to compare the downloaded model against.
+
+ Returns
+ -------
+ (mod, params) : object
+ The Relay representation of the downloaded model.
+ """
+
+ rel_path = f"model_{sha256}.{model_format}"
+ file = tvm.contrib.download.download_testdata(url, rel_path,
overwrite=False)
+
+ # Check SHA-256 hash
+ file_hash = hashlib.sha256()
+ with open(file, "rb") as f:
+ for block in iter(lambda: f.read(4096), b""):
Review Comment:
On my laptop, reading in chunks of `2**24` bytes seems to be the sweet spot,
so I'll use that.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]