SciSharp / TensorFlow.NET

.NET Standard bindings for Google's TensorFlow for developing, training and deploying Machine Learning models in C# and F#.
https://scisharp.github.io/tensorflow-net-docs
Apache License 2.0
3.26k stars 523 forks source link

Non AVX CPU : Suggestions please #539

Closed CrimyTheBold closed 3 years ago

CrimyTheBold commented 4 years ago

(Fantastic work guys with that project)

I have a older CPU that does not support AVX I use the normal (anaconda) Tensorflow 1.x and 2.x with python, works great, with or without GPU (on windows)

My understanding is that some dll in the TF.NET and/or Redist packages (tensorflow.dll ?) is compiled with AVX support that makes this line:

Console.WriteLine($"TensorFlow Binary v{tf.VERSION}", Color.Yellow);

crash with a

The program '[15552] TensorFlowNET.Examples.exe' has exited with code -1073741795 (0xc000001d) 'Illegal Instruction'.

Any suggestion to make it work ? use another precompiled dll ?

CrimyTheBold commented 4 years ago

Update : my CPU is a Westmere (Intel Xeon E5620) supporting MMX, SSE, SSE2, SSE3, SSSE3, SSE4.1, SSE4.2, EM64T, VT-x, AES

Testing a simple program: Console.WriteLine(Environment.OSVersion.ToString()); Console.WriteLine($"TensorFlow Binary v{tf.VERSION}"); Console.WriteLine($"TensorFlow.NET v{Assembly.GetAssembly(typeof(TF_DataType)).GetName().Version}");

testing "raw" : TestHelloWorld.exe `Microsoft Windows NT 6.2.9200.0

Unhandled exception. System.TypeInitializationException: The type initializer for 'Tensorflow.Binding' threw an exception. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.DllNotFoundException: Unable to load DLL 'tensorflow' or one of its dependencies: A dynamic link library (DLL) initialization routine failed. (0x8007045A) at Tensorflow.c_api.TFE_NewContextOptions() at Tensorflow.Eager.ContextOptions..ctor() in C:\Users\Crimy\Source\Repos\TensorFlow.NET-master\src\TensorFlowNET.Core\Eager\ContextOptions.cs:line 8 at Tensorflow.tensorflow..ctor() in C:\Users\Crimy\Source\Repos\TensorFlow.NET-master\src\TensorFlowNET.Core\tensorflow.cs:line 36 --- End of inner exception stack trace --- at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean wrapExceptions, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& hasNoDefaultCtor) at System.RuntimeType.CreateInstanceDefaultCtorSlow(Boolean publicOnly, Boolean wrapExceptions, Boolean fillCache) at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, Boolean wrapExceptions) at System.Activator.CreateInstance[T]() at Tensorflow.Binding.New[T]() in C:\Users\Crimy\Source\Repos\TensorFlow.NET-master\src\TensorFlowNET.Core\Binding.Util.cs:line 116 at Tensorflow.Binding..cctor() in C:\Users\Crimy\Source\Repos\TensorFlow.NET-master\src\TensorFlowNET.Core\Binding.cs:line 10 --- End of inner exception stack trace --- at Tensorflow.Binding.get_tf() in C:\Users\Crimy\Source\Repos\TensorFlow.NET-master\src\TensorFlowNET.Core\Binding.cs:line 10 at TestHelloWorld.Program.Main(String[] args) in C:\Users\Crimy\Source\Repos\TensorFlow.NET-master\TestHelloWorld\Program.cs:line 13 `

testing with Intel Software Development Emulator that can emulate specific instruction set Pretending to have a SandyBridge instead of my Westmere and having AVX emulated: sde.exe -avx 1 -snb -- TestHelloWorld.exe

Microsoft Windows NT 6.2.9200.0 TensorFlow Binary v1.15.1 TensorFlow.NET v0.15.1.0

I could try to compile tensorflow.dll with specific flags, but i dont know how, any help would be appreciated

hu372197979 commented 4 years ago

我也遇到相同问题,求适配!!

CrimyTheBold commented 4 years ago

After some research, my understanding is that the problem is with Tensorflow.dll I tried to rebuild the Tensorflow 1.15 version on my windows. After 10h of fighting with Bazel. I stopped, i suspect that having the real Visual Studio is not the same as having the Visual Build tools only. Next step would be to build an isolated VM dedicated to tensforflow rebuild So the situation is that i can't rebuild TF 1.15 at the moment. Since the main branch of TF.NET is now using TF 2.X, i was wondering if trying to build the 2.X version of TF is not smarter

Hey TF.NET team, any idea on when the 2.X will be done ?

Oceania2018 commented 4 years ago

@CrimyTheBold We're actively developing the 2.0 branch. Some kernel function have been finished, but there still be some hard work to do.

CrimyTheBold commented 4 years ago

@Oceania2018 Thanks for the update. No pressure there, no commitment of any sort required. I guess it's gonna be hard for me to rebuild TF so i think the threshold for me would be 3 months. If TF.NET 2.X is out before 3 months, it's not worth it to try to rebuild TF 1.15. If it's gonna take more than 3 month, i might give TF 1.15 another shot.

Any hint on which version i should work on ?

Oceania2018 commented 4 years ago

Should be stick on 2.x, it's super awesome, check this video.

Paste a latest screenshot for Linear Regression: image