mirror of
https://github.com/tinygrad/tinygrad.git
synced 2026-01-10 07:28:15 -05:00
29 lines
785 B
Python
29 lines
785 B
Python
from tinygrad.tensor import Tensor
|
|
|
|
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) and os.stat(fp).st_size > 0:
|
|
with open(fp, "rb") as f:
|
|
dat = f.read()
|
|
else:
|
|
print("fetching %s" % url)
|
|
dat = requests.get(url).content
|
|
with open(fp+".tmp", "wb") as f:
|
|
f.write(dat)
|
|
os.rename(fp+".tmp", fp)
|
|
return dat
|
|
|
|
def get_parameters(obj):
|
|
parameters = []
|
|
if isinstance(obj, Tensor):
|
|
parameters.append(obj)
|
|
elif isinstance(obj, list):
|
|
for x in obj:
|
|
parameters.extend(get_parameters(x))
|
|
elif hasattr(obj, '__dict__'):
|
|
for k,v in obj.__dict__.items():
|
|
parameters.extend(get_parameters(v))
|
|
return parameters
|
|
|