Framework: Move Ops parameter to call method where possible
还没有人认领这个 Issue。
- 主要语言
- 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 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先检查用于 Initializers、Activations 和 Losses 的框架类,然后比较有状态的 Metrics 和 Optimizers 类。确定哪些类可以在 call 中接收 Ops,而不是在构造时接收,同时仅在状态初始化需要时保留构造函数 Ops。完成的标准是,适用的 API 支持对 Kotlin 友好的调用,并保留预期的作用域和生命周期行为。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- java, kotlin
- 领域
- api, backend-api-design
- Issue 类型
- 重构
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 需要澄清
- 新手友好度
- 20/100