Title: Framework: Move Ops parameter to call method where possible · Issue #202 · tensorflow/java · GitHub
Open Graph Title: Framework: Move Ops parameter to call method where possible · Issue #202 · tensorflow/java
X Title: Framework: Move Ops parameter to call method where possible · Issue #202 · tensorflow/java
Description: 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...
Open Graph Description: 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 sta...
X Description: 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...
Opengraph URL: https://github.com/tensorflow/java/issues/202
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Framework: Move Ops parameter to call method where possible","articleBody":"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.\r\n1. Kotlin interop w/ `@FunctionInterface`. If we do this, we can then define new losses like `Loss{ tf, x -\u003e tf.stuff(x) }` or pass lambdas to methods that take losses. This is very nice for layers, where we might have something Keras-like `Layer(activation=ReLU())` but want to replace it with something custom.\r\n2. 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 `Ops` for (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).\r\n3. 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.\r\n\r\nI'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.","author":{"url":"https://github.com/rnett","@type":"Person","name":"rnett"},"datePublished":"2021-01-31T04:10:45.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":25},"url":"https://github.com/202/java/issues/202"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:5b78722e-ac27-433c-d961-5a95b842715f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E75C:392B41:BD38F9:1043490:696A8922 |
| html-safe-nonce | 9b9ccb06af54a0e7ee2b31e20356c05294c75805329927bd10b2992e85112388 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNzVDOjM5MkI0MTpCRDM4Rjk6MTA0MzQ5MDo2OTZBODkyMiIsInZpc2l0b3JfaWQiOiI3ODAzOTg1NjgyMDI2MzY3MjY2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | d1d928c072a69e5c55327fb75151c3d3c59d5ebe9f97e84ee1607e5150237c17 |
| hovercard-subject-tag | issue:797613515 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/tensorflow/java/202/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4263a9fa9ea0dcc73257c5113788873efcc86f51ea1daf1c56209619eef490a9/tensorflow/java/issues/202 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4263a9fa9ea0dcc73257c5113788873efcc86f51ea1daf1c56209619eef490a9/tensorflow/java/issues/202 |
| og:image:alt | 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 sta... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | rnett |
| hostname | github.com |
| expected-hostname | github.com |
| None | d2aa6dedd7d97fa651b17c40401f2605f309df5ca5fb659bf0554cf34f1de825 |
| turbo-cache-control | no-preview |
| go-import | github.com/tensorflow/java git https://github.com/tensorflow/java.git |
| octolytics-dimension-user_id | 15658638 |
| octolytics-dimension-user_login | tensorflow |
| octolytics-dimension-repository_id | 207384523 |
| octolytics-dimension-repository_nwo | tensorflow/java |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 207384523 |
| octolytics-dimension-repository_network_root_nwo | tensorflow/java |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | c1dbca8981c5e3d6a69bce2f1d289e732b86241d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width