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

AccessViolation when try to cancel ProcessAsync() #23

Closed
kaedei opened this issue Mar 28, 2023 · 3 comments
Closed

AccessViolation when try to cancel ProcessAsync() #23

kaedei opened this issue Mar 28, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@kaedei
Copy link

kaedei commented Mar 28, 2023

Whisper.Net version: 1.2.2
Environment: win10-x64
.NET version: Framework 4.7.2
Model: Small.bin
wav file language: Japanese

Use Whisper.net.Demo sample code, in Program.cs, pass a 1 minute cancellation token to ProcessAsync():

    var cts = new CancellationTokenSource(TimeSpan.FromMinutes(1));
    await foreach (var segment in processor.ProcessAsync(fileStream, cts.Token))
    {
        Console.WriteLine($"New Segment: {segment.Start} ==> {segment.End} : {segment.Text}");
    }

After 1min, the Demo crashed by AccessViolationException:
0x00007FFB245934AE (whisper.dll)处(位于 Whisper.net.Demo.exe 中)引发的异常: 0xC0000005: 读取位置 0x000001D0863A1D90 时发生访问冲突。

@sandrohanea sandrohanea added the bug Something isn't working label Mar 28, 2023
@kaedei
Copy link
Author

kaedei commented Mar 29, 2023

I tried using new Thread() instead of Task.Run() then call processor.Process() in it.
After call thread.Abort(), the thread terminated normally without throwing AccessViolationException.
But Thread.Abort() seems only works in .NET Framework + Windows, this may not be a perfect solution.

@sandrohanea
Copy link
Owner

Yes, the problem is that the underlying whisper.cpp library was not supporting cancellation so even if you cancel whisper.net processor, the processing is still running under the hood. Will check if whisper.cpp have any plans of adding cancellation options. and will keep this updated.

@sandrohanea
Copy link
Owner

I added a commit to fix it and will release it in 1.3.0 version. However, after cancelling, you'll have to call DisposeAsync() instead of Dispose now on the processor as otherwise Dispose method will throw (as the processing is still happening).

DisposeAsync will wait until all resources can be safely released.

Also, a newer encoder will be cancelled now, so the rest of processing will finish faster, but the decoders cannot be cancelled (as whisper.cpp is not supporting that option yet).

sandrohanea added a commit that referenced this issue Nov 25, 2023
 - Improved cancellation using CancellationToken provided => it's using the onabort handler in native library to cancel the processing faster
    => addressing concerns from #23

  - Logging improvements: not logging to stderr by default anymore, but events can be registered (see [LogProvider](https://github.com/sandrohanea/whisper.net/tree/main/Whisper.net/Logger/LogProvider))
     => Added optional logging in simple samples + CoreML sample
     => Logging is now suppressed by default: #129

   - Added `useGpu` on WhisperFactory creation so that GPU usage can be disabled on specific runtimes (e.g. Cublas, CoreML, etc)

   - Upgraded dotnet targets to dotnet 8

   - Added support for whisper large v3 (including downloader + coreml model)
       => Old model Large in downloader should be renamed to LargeV2 see [GgmlType](https://github.com/sandrohanea/whisper.net/blob/main/Whisper.net/Ggml/GgmlType.cs)

   - Added linux-x64 support for Whisper.net.Runtime.Cublas

   - Added support for distil-whisper #126
       => No downloader added, you'll need to load the model yourself
       => How to build the model: https://github.com/ggerganov/whisper.cpp/tree/master/models#distilled-models

   - **Added automated builds for all runtimes using Github Actions**

   - Unified runtime builds with make for linux, macos, ios, tvos, wasm and powershell scripts for windows

   - Added Blazor with InteractivityAuto, InteractivityServer and InteractivityWebAssemly sample with Blazor updated in dotnet 8.

   - Unified Whisper.net.Runtime.Wasm with Whisper.net.Runtime
       => If previously you were using Whisper.net.Runtime.Wasm, just replace it with Whisper.net.Runtime

   - Added metal support for arm-based apple platforms (both Whisper.net.Runtime + Whisper.net.Runtime.CoreML)
sandrohanea added a commit that referenced this issue Nov 25, 2023
* - Upgraded to Whisper.cpp 1.5.1

 - Improved cancellation using CancellationToken provided => it's using the onabort handler in native library to cancel the processing faster
    => addressing concerns from #23

  - Logging improvements: not logging to stderr by default anymore, but events can be registered (see [LogProvider](https://github.com/sandrohanea/whisper.net/tree/main/Whisper.net/Logger/LogProvider))
     => Added optional logging in simple samples + CoreML sample
     => Logging is now suppressed by default: #129

   - Added `useGpu` on WhisperFactory creation so that GPU usage can be disabled on specific runtimes (e.g. Cublas, CoreML, etc)

   - Upgraded dotnet targets to dotnet 8

   - Added support for whisper large v3 (including downloader + coreml model)
       => Old model Large in downloader should be renamed to LargeV2 see [GgmlType](https://github.com/sandrohanea/whisper.net/blob/main/Whisper.net/Ggml/GgmlType.cs)

   - Added linux-x64 support for Whisper.net.Runtime.Cublas

   - Added support for distil-whisper #126
       => No downloader added, you'll need to load the model yourself
       => How to build the model: https://github.com/ggerganov/whisper.cpp/tree/master/models#distilled-models

   - **Added automated builds for all runtimes using Github Actions**

   - Unified runtime builds with make for linux, macos, ios, tvos, wasm and powershell scripts for windows

   - Added Blazor with InteractivityAuto, InteractivityServer and InteractivityWebAssemly sample with Blazor updated in dotnet 8.

   - Unified Whisper.net.Runtime.Wasm with Whisper.net.Runtime
       => If previously you were using Whisper.net.Runtime.Wasm, just replace it with Whisper.net.Runtime

   - Added metal support for arm-based apple platforms (both Whisper.net.Runtime + Whisper.net.Runtime.CoreML)

* Commented local_whisper nuget source + reset github actions to execute against PRs

* Fixed linux build + changed native github actions to work with PRs as well, not only branches

* Add native changes wasm

* Add native changes android

* Add native changes windows

* Add native changes macos

* Updated readme

* Add native changes linux

---------

Co-authored-by: sandrohanea <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants