提交 470fc030 authored 作者: Frederic's avatar Frederic

In the key of the Theano cache, use the md5 hash of the constant value.

We implement it for tensor and sparse Contant Variable. This get also done for gpu variable as it inherit from the tensor Constant variable.
上级 0728bb3c
...@@ -906,6 +906,8 @@ class CLinker(link.Linker): ...@@ -906,6 +906,8 @@ class CLinker(link.Linker):
if isinstance(i, graph.Constant): #orphans if isinstance(i, graph.Constant): #orphans
if id(i) not in constant_ids: if id(i) not in constant_ids:
isig = (i.signature(), topological_pos, i_idx) isig = (i.signature(), topological_pos, i_idx)
if hasattr(isig[0], "theano_hash"):
isig = (isig[0].theano_hash(), topological_pos, i_idx)
try: try:
hash(isig) hash(isig)
except Exception: #generic constants don't have a hashable signature except Exception: #generic constants don't have a hashable signature
......
...@@ -16,6 +16,7 @@ import scipy.sparse ...@@ -16,6 +16,7 @@ import scipy.sparse
from theano import gof, tensor, compile, scalar, config from theano import gof, tensor, compile, scalar, config
from theano.gof.python25 import all from theano.gof.python25 import all
from theano.tensor import blas from theano.tensor import blas
from theano.sparse.utils import hash_from_sparse
sparse_formats = ['csc', 'csr'] sparse_formats = ['csc', 'csr']
...@@ -278,6 +279,10 @@ class SparseConstantSignature(tuple): ...@@ -278,6 +279,10 @@ class SparseConstantSignature(tuple):
(a, b) = self (a, b) = self
return hash(type(self)) ^ hash(a) ^ hash(type(b)) return hash(type(self)) ^ hash(a) ^ hash(type(b))
def theano_hash(self):
(_, d) = self
return hash_from_sparse(d)
class SparseConstant(gof.Constant, _sparse_py_operators): class SparseConstant(gof.Constant, _sparse_py_operators):
dtype = property(lambda self: self.type.dtype) dtype = property(lambda self: self.type.dtype)
......
...@@ -20,6 +20,7 @@ from theano import scalar as scal ...@@ -20,6 +20,7 @@ from theano import scalar as scal
from theano.gof.python25 import partial, any, all from theano.gof.python25 import partial, any, all
from theano import compile, printing from theano import compile, printing
from theano.printing import pprint, min_informative_str from theano.printing import pprint, min_informative_str
from theano.tensor.utils import hash_from_ndarray
# We use these exceptions as well. # We use these exceptions as well.
from theano.scalar import ComplexError, IntegerDivisionError from theano.scalar import ComplexError, IntegerDivisionError
...@@ -1505,6 +1506,10 @@ class TensorConstantSignature(tuple): ...@@ -1505,6 +1506,10 @@ class TensorConstantSignature(tuple):
t, d = self t, d = self
return hashtype(self) ^ hash(t) ^ hash(d.shape) ^ hash(self.sum) return hashtype(self) ^ hash(t) ^ hash(d.shape) ^ hash(self.sum)
def theano_hash(self):
_, d = self
return hash_from_ndarray(d)
def _get_sum(self): def _get_sum(self):
"""Compute sum of non NaN / Inf values in the array.""" """Compute sum of non NaN / Inf values in the array."""
try: try:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论