--
---
You received this message because you are subscribed to the Google Groups "theano-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to theano-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
We can, but I think introducing more reliance on the Python C API is probably contrary to your other stated preferences re: reducing dependence of generated C code on the Python runtime. But, lots of Python objects are being passed around in C code currently, and I don't think adding handling for tuples would add much to the eventual amount for work necessary for such an eventuality.
>
> Does anyone foresee any other subtleties?
>
Quite a lot of use cases, really.In pylearn2, it's pretty common to allow variables passed between methods to be either tuples or theano variables.We use this to represent things like (detector_layer, pooling_layer) of a convolutional network.We're also trying to move pylearn2 beyond the typical setup of having input features X and optionally output targets y.We want to move to setups like having more than one kind of input (example: you have video and audio input) or morethan one kind of output (you're trying to predict a class label, and pose information). From the perspective of writinggeneric pylearn2 code, it makes the most sense for the training algorithm code to just work on a single generic theanovariable called "data". To handle this efficiently, data will need to be a tuple / nested tuple.
The problem is, all of the code acting on such a variable has to have a branch that takes different actions depending onwhether data is a variable or a tuple, because tuples don't have owner, ancestors, name, etc. It's also not possible tosubstitute in a value for a tuple using the givens dictionary.
There's a lot of existing pylearn2 code that could also be greatly simplified by being able to regard multiple theanovariables as one variable. For example, if we could view multiple shared variables as just being one "params"
a lot of the code for stuff like conjugate gradient descent would have way map/reduce operations that need to bewritten out explicitly.
Using a TupleVariable to represent (real, imaginary) would also be an easy way to get complex number support on GPU,provided that you wrote the right helper functions to do complex math on it using real math ops as primitives.
On Tue, Apr 23, 2013 at 9:18 AM, Frédéric Bastien <no...@nouiz.org> wrote:
The main things I want theano to support are:
tuple key to function's updates dictionary
tuple key to function's givens dictionary
tuple in wrt and known_grads of T.grad
create tuple
constant index access of tuple
less important: symbolic index access of tuple
This *enables* end users to do very useful things with the tuple, even if theano
does nothing more.
>> The problem is, all of the code acting on such a variable has to have aMostly because right now our special case code is to just give up on
>> branch that takes different actions depending on
>> whether data is a variable or a tuple, because tuples don't have owner,
>> ancestors, name, etc. It's also not possible to
>> substitute in a value for a tuple using the givens dictionary.
>
>
> Why not just always put the theano variable in a tuple of length one?
doing something useful
if the variable is a tuple. Tuples don't have a name field, for example.
Also because it would be hideously inconvenient to write absolutely
everything that way,
especially compared to modifying a handful of theano functions once
and never worrying
about it again.
> We doIt's not 2 lines, it's NK lines, where N is the number of features we
> that in Theano at a few places to simplify the code. You only add two lines,
ever write in pylearn2,
and K is the number of lines it takes to implement whatever feature of
Type / Variable is
missing from the raw tuple that we wanted to use.
> then you know for sure it is a tuple. Doing a new Variable/Type in Theano ifFor example, a dot product over a tuple of tensors is done by mapping elemwise
> this work around work well is not a good enough reason for the work needed I
> think. Is there reason why this "fix" wouldn't work for pylearn2?
>
>> There's a lot of existing pylearn2 code that could also be greatly
>> simplified by being able to regard multiple theano
>> variables as one variable. For example, if we could view multiple shared
>> variables as just being one "params"
>> a lot of the code for stuff like conjugate gradient descent would have way
>> map/reduce operations that need to be
>> written out explicitly.
>
>
> Sorry, I don't understand the last sentence: "would have way map/reduce
> operations that need to be
> written out explicitly."?
product and summation followed by a reduction with +:
def dot(tuple_A, tuple_B):
return sum((A*B).sum() for A, B in safe_zip(tuple_A, tuple_B))
Doing things like conjugate gradient where you take the dot product
over an unknown
amount of variables requires constantly packing things into tuples for
calling this dot
product function, and then unpacking / flattening them to tell theano
how to do the updates
or take gradients.
On Tue, Apr 23, 2013 at 9:18 AM, Frédéric Bastien <no...@nouiz.org> wrote:I'm thinking of each TupleVariable as being indexable at compile-time using
> Why tuple and not list?
constant indices to get the individual Variables back out.
The container is thus
an important part of the compile-time Variable not just the value it
takes at runtime.
For that to be hashable / immutable, it needs to be a tuple and not a list.
We could also have a variable that represents something that is a list
at runtime,
and can only be interacted with symbolically at runtime, but that has
very different
uses.
--
Pascal