tensorflow / tensorflow/java

Need a way to pass trainable Variables to Optimizer

未关闭
#307 12 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
Java
星标
928
派生
227
PR 合并指标
30 天内没有已合并 PR

描述

In woking with Model training, an issue on Optimizer has shown its head.

Currently, when calling minimize(loss) on the Optimizer instance, the Optimizer code walks the entire Graph and pulls out all the defined Variables in the graph. The idea is when you call minimize(loss), the Optimizer builds gradients based on all the variables. However, when working with Model, this "all variables approach" breaks down, because some variables are not referenced in the loss operand execution path. This produces the following error:

org.tensorflow.exceptions.TFInvalidArgumentException: Cannot compute the partial derivative for node 'model/mse_total' as it's unreachable from the output node(s).

This specific error is because the MSE metric's internal variables are not within the loss execution path. This pattern of "non-trainable variables (weights)" is in most Metric classes, and in the Model itself, so it is wide spread. What we need is a way to distinguish between trainable and non-trainable variables. Trainable variables would then be used to calculate the gradient values in the Optimizer.

In Python tensorflow, the Keras Layers track the trainable variables as an attribute list, the Model then passes the collected lists to the Optimizer's minimize method.

There are a couple of options here:

  1. Mimic TF Keras, and have each Layer identify its trainable variables, Then, pass the trainable variables as a List<Variable<?> list using a call like, Optimizer.minimize(loss, trainableVariables), then have the Optimizer minimize routine call addGradients with this variable list, rather than walk the whole Graph, to compute the gradients.
  2. Within Optimzier.minimize(loss), walk the loss operand execution path to locate any variables contributing to the loss calculation, then pass these to addGradients. A solution based on this option may be facilitated using #232, "Add graph walking functions to Graph and GraphOperation".

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

Start with Optimizer.minimize(loss), its addGradients path, and the Graph/GraphOperation graph-walking work in #232. Compare the two proposed approaches and inspect how Model and Metric variables are represented. Done means a decided API or graph traversal that excludes non-trainable variables and avoids the reported unreachable-node error.

由索引模型根据 Issue 内容生成。

评估

技术栈
java, tensorflow
领域
backend-api-design, machine-learning
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
需要澄清
新手友好度
30/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。