Overloads with constant parameters for ops with often-constant arguments
还没有人认领这个 Issue。
- 主要语言
- 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.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先阅读 ops.proto 中关于 mean、all 和 sum 等归约操作,以及 reshape 和 transpose 的条目,然后将现有的 Helpers API 与拟议的 WrapperHelpers 类进行比较。确定哪些常量参数重载以及哪些 Java 数组或 varargs 形式属于范围。完成的标准是:常见操作接受拟议的常量参数,同时保留默认值,并允许执行所述的构建时检查。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- java, tensorflow
- 领域
- api
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100