Skip to content

Conversation

Copy link

Copilot AI commented Jan 13, 2026

Summary

Converts jni_layer_training.cpp from fbjni to pure JNI, eliminating the fbjni dependency for the Android training module.

C++ (jni_layer_training.cpp):

  • Replace ExecuTorchTrainingJni and SGDHybrid HybridClasses with native handle classes
  • Add TrainingJniCache for cached class/method ID lookups (Tensor, EValue, HashMap, ByteBuffer, ByteOrder, Long/Double/Boolean wrappers)
  • Use standard JNI RegisterNatives instead of fbjni registration

Java (TrainingModule.java, SGD.java):

  • Replace HybridData with long mNativeHandle
  • Remove com.facebook.jni.* imports
  • Add explicit destroy() and finalize() for native resource cleanup

Integration (jni_layer.cpp):

  • Update register_natives_for_training(JNIEnv*) signature to receive env from caller
  • Add using namespace executorch::jni_helper; to fix undeclared identifier build error

Test plan

Code review and CodeQL security scan passed. The JNI layer changes follow the same patterns as PR #16553 which converts the other JNI layers. Full Android build/test requires NDK toolchain.

Original prompt

Spin off a new PR to remove fbjni dependencies from jni_layer_training


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@pytorch-bot
Copy link

pytorch-bot bot commented Jan 13, 2026

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/16556

Note: Links to docs will display an error until the docs builds have been completed.

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jan 13, 2026
@github-actions
Copy link

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

Copilot AI and others added 3 commits January 13, 2026 08:07
- Convert jni_layer_training.cpp from fbjni to pure JNI
- Replace HybridClass with native handle pattern
- Replace fbjni method registration with RegisterNatives
- Update TrainingModule.java to use long mNativeHandle
- Update SGD.java to use long mNativeHandle
- Add finalize() and destroy() methods for cleanup
- Update jni_layer.cpp to pass JNIEnv* to training registration

Co-authored-by: kirklandsign <[email protected]>
Copilot AI changed the title [WIP] Remove fbjni dependencies from jni_layer_training Remove fbjni dependencies from jni_layer_training Jan 13, 2026
Copilot AI requested a review from kirklandsign January 13, 2026 08:19
@kirklandsign
Copy link
Contributor

@copilot error: use of undeclared identifier 'jni_helper'; did you mean 'executorch::jni_helper'?

Copy link
Author

Copilot AI commented Jan 13, 2026

@copilot error: use of undeclared identifier 'jni_helper'; did you mean 'executorch::jni_helper'?

Fixed in a3969e1 by adding using namespace executorch::jni_helper; to jni_layer.cpp.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants