Framework: Move Ops parameter to call method where possible
まだ誰も着手していません。
- 主要言語
- Java
- スター
- 928
- フォーク
- 227
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
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.
- Kotlin interop w/
@FunctionInterface. If we do this, we can then define new losses likeLoss{ 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-likeLayer(activation=ReLU())but want to replace it with something custom. - 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
Opsfor (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). - 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.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず Initializers、Activations、Losses のフレームワーククラスを確認し、次に状態を持つ Metrics クラスと Optimizers クラスを比較します。構築時ではなく call で Ops を受け取れるクラスを特定し、状態の初期化に必要な場合にのみコンストラクターの Ops を残します。対象となる API が Kotlin に適した呼び出しをサポートし、意図されたスコープとライフタイムの動作を維持できれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- java, kotlin
- 領域
- api, backend-api-design
- issue の種類
- リファクタリング
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- 説明が足りない
- 初心者へのやさしさ
- 20/100