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

[BUG Report]: Tensorflow.RuntimeError: Tensorflow.NET cannot find a backend despite having installed SciSharp.TensorFlow.Redist on macOS M1 #1249

Open
mariuszmatusiak opened this issue May 19, 2024 · 5 comments

Comments

@mariuszmatusiak
Copy link

Description

I installed all the Tensorflow.NET components according to the documentation on my M1. I am working in Visual Studio Code.
Despite having installed all the required packages: SciSharp.TensorFlow.Redist, TensorFlow.Keras, TensorFlow.NET, and even Microsoft.ML.TensorFlow.Redist as mentioned in one of the similar threads (#252) I am still unable to get this work.

Part of my *.csproj file:

<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">11.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">13.1</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>

...

<ItemGroup>
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
<PackageReference Include="Microsoft.ML.TensorFlow.Redist" Version="0.14.0" />
<PackageReference Include="SciSharp.TensorFlow.Redist" Version="2.16.0" />
<PackageReference Include="TensorFlow.Keras" Version="0.15.0" />
<PackageReference Include="TensorFlow.NET" Version="0.150.0" />
</ItemGroup>

Part of my *.xaml.cs file:

using static Tensorflow.Binding;
using static Tensorflow.KerasApi;
using Tensorflow;
using Tensorflow.NumPy;
...
var hello = tf.constant("yey!"); // <- AN EXCEPTION THROWN HERE
Console.WriteLine(hello);
Screenshot 2024-05-19 at 12 35 57

Exception thrown: 'System.DllNotFoundException' in Tensorflow.Binding.dll

Exception thrown: 'Tensorflow.RuntimeError' in Tensorflow.Binding.dll

Reproduction Steps

  1. Create a new .NET MAUI project on macOS M1
  2. Install ML.NET: dotnet tool install -g mlnet-osx-arm64
  3. Install TF.NET: dotnet add package TensorFlow.NET
  4. Install TF.Keras: dotnet add package TensorFlow.Keras
  5. Install SciSharp.TensorFlow.Redist: dotnet add package SciSharp.TensorFlow.Redist
  6. Install Microsoft.ML.TensorFlow.Redist: dotnet add package Microsoft.ML.TensorFlow.Redist
  7. Add using static Tensorflow.Binding; and an example call in a project source file.

Known Workarounds

No response

Configuration and Other Information

TensorFlow.NET version=0.150.0
dotnet version=8.0.204

OS Name: Mac OS X
OS Version: 14.4
OS Platform: Darwin
RID: osx-arm64
Base Path: /usr/local/share/dotnet/sdk/8.0.204/

.NET workloads installed:
[maui]
Installation Source: SDK 8.0.200
Manifest Version: 8.0.7/8.0.100
Manifest Path: /usr/local/share/dotnet/sdk-manifests/8.0.100/microsoft.net.sdk.maui/8.0.7/WorkloadManifest.json
Install Type: FileBased

.NET SDKs installed:
6.0.404 [/usr/local/share/dotnet/sdk]
7.0.101 [/usr/local/share/dotnet/sdk]
8.0.204 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.12 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.1 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.4 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.12 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.1 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.4 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

@AsakusaRinne
Copy link
Collaborator

@Oceania2018 Does redist 2.16.0 include a MAC backend when publishing it?

@Lionberg
Copy link

Lionberg commented Jun 1, 2024

The same issue with simple console app example:

class Program
    {
        static void Main(string[] args)
        {
            var hello = tf.constant("Hello, TensorFlow!");
            Console.WriteLine(hello);
        }
    }

Installed packs:

      <PackageReference Include="SciSharp.TensorFlow.Redist" Version="2.16.0" />
      <PackageReference Include="TensorFlow.NET" Version="0.150.0" />

Exception:
Tensorflow.RuntimeError: Tensorflow.NET cannot find a backend. Please install one of the following packages for your program: SciSharp.TensorFlow.Redist, SciSharp.TensorFlow.Redist-Linux-GPU, SciSharp.TensorFlow.Redist-Windows-GPU

MacOS, M2 Ultra.

@agene0001
Copy link

I got the same problem as well

using System;
using static Tensorflow.Binding;

/// <summary>
/// Simple hello world using TensorFlow
/// </summary>
class Program
{
    static void Main(string[] args)
    {
        var hello = tf.constant("Hello, TensorFlow!");
        Console.WriteLine(hello);
    }
}

Installed packs:

  <PackageReference Include="SciSharp.TensorFlow.Redist" Version="2.16.0" />
  <PackageReference Include="TensorFlow.NET" Version="0.150.0" />

Exception:
Tensorflow.NET cannot find a backend. Please install one of the following packages for your program: SciSharp.TensorFlow.Redist, SciSharp.TensorFlow.Redist-Linux-GPU, SciSharp.TensorFlow.Redist-Windows-GPU.
MacOS, M2 Ultra.

@Folasayo-Samuel
Copy link

To resolve the issue in your macOS:

CPU version for MacOS

PM> Install-Package SciSharp.TensorFlow.Redist-OSX

This should resolve the issue.
@Lionberg @mariuszmatusiak @AsakusaRinne @agene0001 @henon

@mariuszmatusiak
Copy link
Author

mariuszmatusiak commented Aug 25, 2024

To resolve the issue in your macOS:

CPU version for MacOS

PM> Install-Package SciSharp.TensorFlow.Redist-OSX

This should resolve the issue. @Lionberg @mariuszmatusiak @AsakusaRinne @agene0001 @henon

@Folasayo-Samuel unfortunately it didn't helped me. I don't have PowerShell on Mac, so I ran
dotnet add package SciSharp.TensorFlow.Redist-OSX
inside my app folder. A package reference was added successfully in version 2.15.0, but when I debug the app it still throws the exception.
I checked the content of the package on https://nuget.info/packages/SciSharp.TensorFlow.Redist-OSX/2.15.0 and it contains binaries only inside the osx-x64 folder. There is no osx-arm64. I guess this might be the issue.

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

5 participants