-
-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split Cuda to Windows + Linux and added Parallel Example
- Loading branch information
Sandro Hanea
committed
Oct 8, 2024
1 parent
fc1282f
commit bc6ad14
Showing
14 changed files
with
167 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0"?> | ||
<package> | ||
<metadata> | ||
<id>Whisper.net.Runtime.Cuda.Linux</id> | ||
<title>Whisper.Net.Runtime.Cuda.Linux</title> | ||
<version>1.7.0</version> | ||
<authors>Sandro Hanea</authors> | ||
<owners>Sandro Hanea</owners> | ||
<requireLicenseAcceptance>false</requireLicenseAcceptance> | ||
<summary>Linux Cuda dotnet runtimes for Whisper.</summary> | ||
<description>Whisper.net.Runtime.Cuda.Linux contains the native runtime libraries to enable Whisper on .NET with Whisper.net and GPU support (Cuda) for Linux</description> | ||
<tags>whisper;cuda;gpu;cublas;</tags> | ||
<projectUrl>https://github.com/sandrohanea/whisper.net</projectUrl> | ||
<license type="expression">MIT</license> | ||
</metadata> | ||
<files> | ||
<file src="Whisper.net.Runtime.Cuda.Linux\**" target="build"/> | ||
</files> | ||
</package> |
15 changes: 1 addition & 14 deletions
15
...ime.Cuda/Whisper.net.Runtime.Cuda.targets → ...ux/Whisper.net.Runtime.Cuda.Linux.targets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0"?> | ||
<package> | ||
<metadata> | ||
<id>Whisper.net.Runtime.Cuda.Windows</id> | ||
<title>Whisper.Net.Runtime.Cuda.Windows</title> | ||
<version>1.7.0</version> | ||
<authors>Sandro Hanea</authors> | ||
<owners>Sandro Hanea</owners> | ||
<requireLicenseAcceptance>false</requireLicenseAcceptance> | ||
<summary>Windows Cuda dotnet runtimes for Whisper.</summary> | ||
<description>Whisper.net.Runtime.Cuda.Windows contains the native runtime libraries to enable Whisper on .NET with Whisper.net and GPU support (Cuda) on Windows.</description> | ||
<tags>whisper;cuda;gpu;cublas;</tags> | ||
<projectUrl>https://github.com/sandrohanea/whisper.net</projectUrl> | ||
<license type="expression">MIT</license> | ||
</metadata> | ||
<files> | ||
<file src="Whisper.net.Runtime.Cuda.Windows\**" target="build"/> | ||
</files> | ||
</package> |
16 changes: 16 additions & 0 deletions
16
Whisper.net.Runtime.Cuda.Windows/Whisper.net.Runtime.Cuda.Windows.targets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<ItemGroup> | ||
<None Visible="false" Include="$(MSBuildThisFileDirectory)win-x64\whisper.dll"> | ||
<Pack>true</Pack> | ||
<PackageCopyToOutput>true</PackageCopyToOutput> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
<TargetPath>runtimes/cuda/win-x64/whisper.dll</TargetPath> | ||
</None> | ||
<None Visible="false" Include="$(MSBuildThisFileDirectory)win-x64\ggml.dll"> | ||
<Pack>true</Pack> | ||
<PackageCopyToOutput>true</PackageCopyToOutput> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
<TargetPath>runtimes/cuda/win-x64/ggml.dll</TargetPath> | ||
</None> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFrameworks>net8.0; net472</TargetFrameworks> | ||
<LangVersion>12</LangVersion> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Whisper.net.Runtime" Version="1.7.0" /> | ||
<PackageReference Include="Whisper.net" Version="1.7.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Include="../TestData/kennedy.wav"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Licensed under the MIT license: https://opensource.org/licenses/MIT | ||
|
||
using System; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using Whisper.net; | ||
using Whisper.net.Ggml; | ||
using Whisper.net.Logger; | ||
|
||
public class Program | ||
{ | ||
// This examples shows how to use Whisper.net to create a transcription from an audio file with 16Khz sample rate with 2 parallel executions. | ||
public static async Task Main(string[] args) | ||
{ | ||
var ggmlType = GgmlType.Base; | ||
var modelFileName = "ggml-base.bin"; | ||
|
||
if (!File.Exists(modelFileName)) | ||
{ | ||
await DownloadModel(modelFileName, ggmlType); | ||
} | ||
|
||
// Optional logging from the native library | ||
LogProvider.Instance.OnLog += (level, message) => | ||
{ | ||
Console.Write($"{level}: {message}"); | ||
}; | ||
|
||
// This section creates the whisperFactory object which is used to create the processor object. | ||
using var whisperFactory = WhisperFactory.FromPath("ggml-base.bin"); | ||
|
||
var task1 = Task.Run(() => RunInParallel("Task1", "kennedy.wav", whisperFactory)); | ||
var task2 = Task.Run(() => RunInParallel("Task2", "kennedy.wav", whisperFactory)); | ||
|
||
// We wait both tasks and we'll see that the results are interleaved | ||
await Task.WhenAll(task1, task2); | ||
} | ||
|
||
public static async Task RunInParallel(string name, string wavFileName, WhisperFactory whisperFactory) | ||
{ | ||
|
||
// This section creates the processor object which is used to process the audio file, it uses language `auto` to detect the language of the audio file. | ||
using var processor = whisperFactory.CreateBuilder() | ||
.WithLanguage("auto") | ||
.Build(); | ||
|
||
using var fileStream = File.OpenRead(wavFileName); | ||
|
||
// This section processes the audio file and prints the results (start time, end time and text) to the console. | ||
await foreach (var result in processor.ProcessAsync(fileStream)) | ||
{ | ||
Console.WriteLine($"{name} =====> {result.Start}->{result.End}: {result.Text}"); | ||
|
||
// Add some delay, otherwise we might get the results too fast | ||
await Task.Delay(1000); | ||
} | ||
} | ||
|
||
private static async Task DownloadModel(string fileName, GgmlType ggmlType) | ||
{ | ||
Console.WriteLine($"Downloading Model {fileName}"); | ||
using var modelStream = await WhisperGgmlDownloader.GetGgmlModelAsync(ggmlType); | ||
using var fileWriter = File.OpenWrite(fileName); | ||
await modelStream.CopyToAsync(fileWriter); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<packageSources> | ||
<clear /> | ||
<add key="public_nugget" value="https://api.nuget.org/v3/index.json" /> | ||
<add key="Local Whisper" value="C:\Projects\sandrohanea\whisper.net\nupkgs" /> | ||
</packageSources> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters