tensorflow / tensorflow/java

Overloads with constant parameters for ops with often-constant arguments

Aperta
#163 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
Java
Stelle
928
Fork
227
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia leggendo le voci di ops.proto per le operazioni di riduzione come mean, all e sum, oltre a reshape e transpose, quindi confronta l'API Helpers esistente con la classe WrapperHelpers proposta. Determina quali overload con parametri costanti e quali forme di array Java o varargs rientrano nell'ambito. Il lavoro è completato quando le operazioni comuni accettano gli argomenti costanti proposti, preservando i valori predefiniti e consentendo i controlli indicati in fase di build.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
java, tensorflow
Ambito
api
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.