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

How to update torch for this plugin ? #28

Open
MohamedAliRashad opened this issue May 15, 2023 · 1 comment
Open

How to update torch for this plugin ? #28

MohamedAliRashad opened this issue May 15, 2023 · 1 comment

Comments

@MohamedAliRashad
Copy link

@fynnmaarten I am trying to load a model that i compiled using PyTorch 2.0.0 and it is giving me an error.
How to update the torch version for this plugin ?

@cyrillkuettel
Copy link

cyrillkuettel commented May 15, 2023

Updating Pytorch Version of the plugin

I did this a couple of months ago, so here you go:

(Disclaimer: this can be quite a hustle, it's probably easier to compile with pytorch 1.10 if that's an option that works for you.)

  1. Fork this repository to have a local copy.
  2. Open your project's pubspec.yml and update the version to the forked one.
flutter_pytorch_mobile:
    git: git@github.com:name/path-to-your-forked-repo.git

iOS

Open flutter_pytorch_mobile/ios/flutter_pytorch_mobile.podspec in your forked plugin.
Change the version you want to change, on iOS it's called LibTorch

  @ ios/flutter_pytorch_mobile.podspec:27 @ A new Flutter plugin project.
  s.static_framework = true
  s.public_header_files = 'Classes/**/*.h'

-  s.dependency 'LibTorch', '~>1.10.0'
+  s.dependency 'LibTorch', '~>1.13.0'
    # Flutter.framework does not contain a i386 slice.
  s.pod_target_xcconfig = { 'DEFINES_MODULE' =>

Here we've changed the dependency s.dependency 'LibTorch to 1.13 as an example.
❗ You'll to check which version you need that works with PyTorch 2.0.0

After that, run

pod update LibTorch

for the changes to take effect (If you don't have pod, you need to install Cocabods)

Maybe you also need:

flutter build ios

Android

On android, pytorch mobile is specified as a gradle dependency in your forked plugin.
Open flutter_pytorch_mobile/android/build.gradle

dependencies {
    implementation 'org.pytorch:pytorch_android:1.13.1'
    implementation 'org.pytorch:pytorch_android_torchvision:1.13.1
}

After that, sync gradle and make sure everything works in the Android build. It usually helps opening Android Studio and resolving all issues.
Finally, don't forget to commit and push your changes.

DenDen047 added a commit to DenDen047/flutter_pytorch_mobile that referenced this issue Oct 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants