Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HuggingFaceTokenizer android load #2170

Closed
soonguKwon opened this issue Nov 20, 2022 · 11 comments · Fixed by #3531
Closed

HuggingFaceTokenizer android load #2170

soonguKwon opened this issue Nov 20, 2022 · 11 comments · Fixed by #3531
Labels

Comments

@soonguKwon
Copy link

Description

I tried to load HuggingFaceTokenizer on android but failed.

HuggingFaceTokenizer tokenizer = HuggingFaceTokenizer.newInstance(assetFilePath(this, "tokenizer.json"), options);

Error Message

ai.djl.engine.EngineException: Failed to load Huggingface native library.

@soonguKwon soonguKwon added the bug Something isn't working label Nov 20, 2022
@frankfliu
Copy link
Contributor

Currently Huggingface Tokenizer extension is not available for Android. We only added PyTorch and OnnxRuntime to Android.

@frankfliu frankfliu added enhancement New feature or request Call for Contribution and removed bug Something isn't working labels Nov 20, 2022
@soonguKwon
Copy link
Author

Do you have any support plans?

Currently Huggingface Tokenizer extension is not available for Android. We only added PyTorch and OnnxRuntime to Android.

@frankfliu
Copy link
Contributor

We don't have bandwidth currently. It shouldn't be hard to add Android support. No java code change is needed. The most of work is setup CI to build android native library. We can work with you if you want to contribute.

@BigSquirrel2000
Copy link

BigSquirrel2000 commented Dec 2, 2022

@frankfliu do you know if someone is already working on this?

@lanking520
Copy link
Contributor

@BigSquirrel2000
Copy link

BigSquirrel2000 commented Dec 6, 2022

currently I managed to recompile rust

but during System.loadLibrary("tokenizers") in android emulator, following error occurs:
java.lang.UnsatisfiedLinkError: dlopen failed: library "libc++_shared.so" not found: needed by /lib/x86_64/libtokenizers.so in namespace classloader-namespace

any clues what could be a solution?

@BigSquirrel2000
Copy link

update: it seems like gradle issue gradle/gradle#23023
for that moment, quickfix described in above issue - seems to work.

@lanking520
Copy link
Contributor

Thanks for your discovery @BigSquirrel2000. Are you willing to contribute your working solution to DJL repo? For Android NDK build

@naveen521kk
Copy link
Contributor

naveen521kk commented Nov 16, 2024

Hey, I would like to contribute to this issue. I came across this library while looking for a way to run the tokenizer in my Android app project.

I've figured out how to build the rust library using cargo-ndk. However, I wasn't able to figure out how to build OpenSSL, so I've disabled the functions which will use Hugging Face API - that is only local paths would work on Android. I've also created a build native library for Android like pytorch-native to distribute the rust library.

See https://github.com/deepjavalibrary/djl/compare/master...naveen521kk:djl:tokenizer-android-support?expand=1 for the changes I made.

I've tested the resultant build output in my Android app and it works - made a small wrapper for it in react native too.

I could make a PR out of that branch if someone could help me configure the CI.

Thanks!

cc @frankfliu

@frankfliu
Copy link
Contributor

@naveen521kk

Really appreciate for your contribution. Your changes looks great, and I tried locally, it works. Please raise a PR, once it merged, we can add CI to publish it.

@naveen521kk
Copy link
Contributor

@naveen521kk

Really appreciate for your contribution. Your changes looks great, and I tried locally, it works. Please raise a PR, once it merged, we can add CI to publish it.

Hey, I've created #3531, have a look at it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants