tensorflow / tensorflow/java

Framework: Move Ops parameter to call method where possible

Aperta
#202 25 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

I'd like to move the Ops parameters of framework classes to the call method, where possible. This is primarily for Kotlin interop, but has a few other benefits as well. It won't be possible for stateful classes (Metrics, Optimizers), but should be possible for most, as far as I can tell (Initializers, Activations, Losses). I'm going to use Losses as a standin for all 3 for my examples.

  1. Kotlin interop w/ @FunctionInterface. If we do this, we can then define new losses like Loss{ tf, x -> tf.stuff(x) } or pass lambdas to methods that take losses. This is very nice for layers, where we might have something Keras-like Layer(activation=ReLU()) but want to replace it with something custom.
  2. Re-use of objects. Currently, losses create any subsequent calls in the same scope as their first call. That means if it's called inside a sub-scope, including device ones, it ignores the scope. This is somewhat expected, but not ideal. It also causes further issues if we use Ops for (eager) tensor lifetime management, which has been suggested and is something I'd like to do (it's easy enough to make a long-lived copy of the initial scope, but then the tensors created in the call methods live forever, and the framework classes need to be closable).
  3. Passing configs, like Keras. In Keras, if you have a activation or loss that requires some parameters, you can pass it to a layer like Layer(activation=LeakyReLU(alpha=0.3)). I expect this will be common with our API, as well. Currently, this runs into the above issue w/ scoping, and prevents you from passing activations (or losses) from scopes that don't have an Ops instance available.

I'd look at having the stateful classes take Ops in call as well, and only using the constructor ops for initializing state. This works better with scoping and lifetimes as mentioned above.

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 esaminando le classi del framework per Initializers, Activations e Losses, quindi confronta le classi con stato Metrics e Optimizers. Determina quali classi possono ricevere Ops in call anziché durante la costruzione, mantenendo gli Ops del costruttore solo dove sono necessari per l'inizializzazione dello stato. Il lavoro è completo quando le API applicabili supportano chiamate compatibili con Kotlin e preservano il comportamento previsto per lo scope e il ciclo di vita.

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

Valutazione

Stack tecnologico
java, kotlin
Ambito
api, backend-api-design
Tipo di issue
Refactoring
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
20/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.