An error message has 4 parts:
Here is an example of code with a user error. Don't try to find the error by code inspection, check only the error:
In [1]:
import numpy as np
import theano
import theano.tensor as T
x = T.vector()
y = T.vector()
z = x + x
z = z * y
f = theano.function([x, y], z)
f(np.ones((2,)), np.ones((3,)))
In [ ]:
# TODO: finish to define the mode below
mode=...
import numpy as np
import theano
import theano.tensor as T
x = T.vector()
y = T.vector()
z = x + x
z.name = "z1"
z = z * y
z.name = "z2"
f = theano.function([x, y], z, mode=mode)
f(np.ones((2,)), np.ones((3,)))
Checks and double-checks everything, extremely slow.
Use the Theano flag mode=DebugMode
or the the parameter mode=theano.compile.DebugMode()
to theano.function()
.
PDB is similar to GDB
n
: nextc
: continuel
: listp var
: prints
: step,bt
: print the stack traceTo get into PDB:
import pdb; pdb.set_trace()
python -m pdb script.py
To get into PDB with Theano:
mode=FAST_COMPILE
disables most of optimizations, and C code generation.linker=py
disables C code generation.warn_float64=pdb
PdbBreakpoint
: breakpoint during execution.
In [ ]:
import theano
import theano.tensor as T
from theano.tests.breakpoint import PdbBreakpoint
input, target = T.fvectors(['x', 'y'])
mse = (input - target) ** 2
# Conditional breakpoint to be activated if the total
# MSE > 100. The breakpoint will monitor the inputs,
# targets as well as the individual error values
breakpointOp = PdbBreakpoint("MSE too high")
condition = T.gt(mse.sum(), 100)
mse, monitored_input, monitored_target = breakpointOp(
condition, mse, input, target)
# Compile the theano function
fct = theano.function([input, target], mse)
# Use the function
print fct([10, 0], [10, 5]) # Will NOT activate the breakpoint
print fct([0, 0], [10, 5]) # Will activate the breakpoint
In [ ]:
import theano
x = theano.tensor.vector()
o = theano.printing.Print("a message")(x)
f = theano.function([x], o)
d = f([3, 4])
In [ ]:
o = theano.printing.Print("Attributes of x:", attrs=('min', 'mean', 'max'))(x)
f = theano.function([x], o)
d = f([3, 1, 4, 9])
In [ ]:
import numpy
import theano
import theano.compile.nanguardmode
from theano import tensor as T
x = T.matrix()
w = theano.shared(numpy.random.randn(5, 7).astype(theano.config.floatX))
y = T.dot(x, w)
mode=theano.compile.nanguardmode.NanGuardMode(nan_is_error=True,
inf_is_error=True,
big_is_error=True)
fun = theano.function(
[x], y, mode=mode)
infa = numpy.tile(
(numpy.asarray(100.) ** 1000000), (3, 5))
fun(infa)
In [ ]:
# Can also be 'off', 'ignore', 'raise', 'pdb'
theano.config.compute_test_value = 'warn'
# input which will be of shape (5, 10)
x, y = T.matrices('xy')
# provide Theano with a default test-value
x.tag.test_value = numpy.random.rand(5, 10)
y.tag.test_value = numpy.random.rand(4, 10)
x + y # warn about the shape error
theano.tensor.opt.AssertOp
theano.printing.{debugprint,pydotprint}
profile=True
exception_verbosity=True
MemoryError
warn_float64='pdb'
float64
are build in the graphon_opt_error=True
optimizer_verbose=True