tensorflow / tensorflow/java

Overloads with constant parameters for ops with often-constant arguments

オープン
#163 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
Java
スター
928
フォーク
227
PR マージ指標
30日以内にマージされた PR はありません

説明

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.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、mean、all、sum などの reduction ops、および reshape と transpose について ops.proto のエントリを読み、既存の Helpers API と提案されている WrapperHelpers クラスを比較します。どの定数パラメータのオーバーロードと、Java の配列または varargs の形式が対象になるかを判断します。一般的な操作が提案された定数引数を受け付け、デフォルトを維持し、指定されたビルド時チェックを可能にすれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
java, tensorflow
領域
api
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。