From 23c39d9f526b9e0e6f45857b9d9fea067e75a465 Mon Sep 17 00:00:00 2001 From: Manjeet Singh Date: Sat, 7 Nov 2020 23:15:10 +0530 Subject: [PATCH] fetch() 'ran out of input' fix (#65) If requests.get fails during a download, the incomplete file is passed without a size check. This causes errors during image/model loading. Not sure if this is a problem on all systems. --- tinygrad/utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tinygrad/utils.py b/tinygrad/utils.py index 8fe2bb73..691030d0 100644 --- a/tinygrad/utils.py +++ b/tinygrad/utils.py @@ -1,4 +1,5 @@ import numpy as np +import os def mask_like(like, mask_inx, mask_value = 1.0): mask = np.zeros_like(like).reshape(-1) @@ -12,7 +13,7 @@ def layer_init_uniform(*x): def fetch(url): import requests, os, hashlib, tempfile fp = os.path.join(tempfile.gettempdir(), hashlib.md5(url.encode('utf-8')).hexdigest()) - if os.path.isfile(fp): + if os.path.isfile(fp) and os.stat(fp).st_size > 0: with open(fp, "rb") as f: dat = f.read() else: