tensorflow / tensorflow/java

Overloads with constant parameters for ops with often-constant arguments

Abierto
#163 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Lenguaje dominante
Java
Estrellas
928
Forks
227
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

System information

  • Version: master
  • Are you willing to contribute it: Yes

Describe the feature and the current behavior/state.

There's a good amount of ops that take indices, shapes, permutations, scalars, or some kind of often constant value as inputs. Currently, these have to be converted to operand, which results in lots of wrapping and prevents the use of defaults (things like reducing all dimensions if none are specified, for reduce ops). Examples include all the reduction ops (mean, all, sum), reshape, and transpose (permute),

Will this change the current api? How?

I'd like to create a WrapperHelpers class, like Helpers, to create Ops methods that take Java arrays, or varargs where possible, for the most common of these Ops.

For example:

// Current API
tf.math.mean(x, tf.array(0, 1, 2));
// With wrappers
tf.math.mean(x, new long{0, 1, 2});
// OR, if it's a rank 3 array
tf.math.mean(x, null);

Who will benefit with this feature?

Anyone using these ops (and they are common ops). This isn't a huge improvement in size (the example is actually longer), the biggest improvement is from being able to use defaults for empty arrays or nulls. We can do build-time Java-side error checking for things like repeated indices. For rank-dependent inputs like for transpose this is especially useful.

It also helps out a Kotlin API a bit, since we aren't using the Options vararg and so can use it for this. Something like tf.math.mean(x, 2, 3, keepDims = true) or x.mean(2, 3, keepDims = true) eventually.

Any Other info.

I experimented with codegen for this, as these inputs are marked with Tidx or similar in ops.proto, however many different types of indices or shapes are used (i.e. 2D for BatchToSpace or 1D for reduce) with no distinction, so I don't think it's possible to generate these wrappers.

If this goes well, I'd also like to look at creating similar methods to wrap scalars for math ops, i.e. x.add(2), since I suspect they will be commonly used.

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Empieza leyendo las entradas de ops.proto para operaciones de reducción como mean, all y sum, además de reshape y transpose; después compara la API Helpers existente con la clase WrapperHelpers propuesta. Determina qué sobrecargas con parámetros constantes y qué formas de arrays de Java o varargs están incluidas en el alcance. Se considera terminado cuando las operaciones comunes aceptan los argumentos constantes propuestos, conservan los valores predeterminados y permiten las comprobaciones indicadas durante la compilación.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
java, tensorflow
Área
api
Tipo de issue
Nueva funcionalidad
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.