whispercpp 1.2.0.2 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +5 -0
  3. data/LICENSE +1 -1
  4. data/README.md +165 -434
  5. data/Rakefile +46 -86
  6. data/ext/.gitignore +13 -0
  7. data/ext/cpu.mk +9 -0
  8. data/ext/{dr_wav.h → examples/dr_wav.h} +3560 -1179
  9. data/ext/extconf.rb +185 -7
  10. data/ext/ggml/include/ggml-alloc.h +76 -0
  11. data/ext/ggml/include/ggml-backend.h +352 -0
  12. data/ext/ggml/include/ggml-blas.h +25 -0
  13. data/ext/ggml/include/ggml-cann.h +123 -0
  14. data/ext/ggml/include/ggml-cpp.h +38 -0
  15. data/ext/ggml/include/ggml-cpu.h +135 -0
  16. data/ext/ggml/include/ggml-cuda.h +47 -0
  17. data/ext/ggml/include/ggml-kompute.h +50 -0
  18. data/ext/ggml/include/ggml-metal.h +66 -0
  19. data/ext/ggml/include/ggml-opencl.h +26 -0
  20. data/ext/ggml/include/ggml-opt.h +216 -0
  21. data/ext/ggml/include/ggml-rpc.h +28 -0
  22. data/ext/ggml/include/ggml-sycl.h +49 -0
  23. data/ext/ggml/include/ggml-vulkan.h +31 -0
  24. data/ext/ggml/include/ggml.h +2285 -0
  25. data/ext/ggml/src/ggml-alloc.c +1037 -0
  26. data/ext/ggml/src/ggml-amx/common.h +94 -0
  27. data/ext/ggml/src/ggml-amx/ggml-amx.cpp +446 -0
  28. data/ext/ggml/src/ggml-amx/mmq.cpp +2510 -0
  29. data/ext/ggml/src/ggml-amx/mmq.h +17 -0
  30. data/ext/ggml/src/ggml-backend-impl.h +256 -0
  31. data/ext/ggml/src/ggml-backend-reg.cpp +552 -0
  32. data/ext/ggml/src/ggml-backend.cpp +1999 -0
  33. data/ext/ggml/src/ggml-blas/ggml-blas.cpp +517 -0
  34. data/ext/ggml/src/ggml-cann/acl_tensor.cpp +175 -0
  35. data/ext/ggml/src/ggml-cann/acl_tensor.h +258 -0
  36. data/ext/ggml/src/ggml-cann/aclnn_ops.cpp +3427 -0
  37. data/ext/ggml/src/ggml-cann/aclnn_ops.h +592 -0
  38. data/ext/ggml/src/ggml-cann/common.h +286 -0
  39. data/ext/ggml/src/ggml-cann/ggml-cann.cpp +2188 -0
  40. data/ext/ggml/src/ggml-cann/kernels/ascendc_kernels.h +19 -0
  41. data/ext/ggml/src/ggml-cann/kernels/dup.cpp +236 -0
  42. data/ext/ggml/src/ggml-cann/kernels/get_row_f16.cpp +197 -0
  43. data/ext/ggml/src/ggml-cann/kernels/get_row_f32.cpp +190 -0
  44. data/ext/ggml/src/ggml-cann/kernels/get_row_q4_0.cpp +204 -0
  45. data/ext/ggml/src/ggml-cann/kernels/get_row_q8_0.cpp +191 -0
  46. data/ext/ggml/src/ggml-cann/kernels/quantize_f16_q8_0.cpp +218 -0
  47. data/ext/ggml/src/ggml-cann/kernels/quantize_f32_q8_0.cpp +216 -0
  48. data/ext/ggml/src/ggml-cann/kernels/quantize_float_to_q4_0.cpp +295 -0
  49. data/ext/ggml/src/ggml-common.h +1853 -0
  50. data/ext/ggml/src/ggml-cpu/amx/amx.cpp +220 -0
  51. data/ext/ggml/src/ggml-cpu/amx/amx.h +8 -0
  52. data/ext/ggml/src/ggml-cpu/amx/common.h +91 -0
  53. data/ext/ggml/src/ggml-cpu/amx/mmq.cpp +2511 -0
  54. data/ext/ggml/src/ggml-cpu/amx/mmq.h +10 -0
  55. data/ext/ggml/src/ggml-cpu/cpu-feats-x86.cpp +323 -0
  56. data/ext/ggml/src/ggml-cpu/ggml-cpu-aarch64.cpp +4262 -0
  57. data/ext/ggml/src/ggml-cpu/ggml-cpu-aarch64.h +8 -0
  58. data/ext/ggml/src/ggml-cpu/ggml-cpu-hbm.cpp +55 -0
  59. data/ext/ggml/src/ggml-cpu/ggml-cpu-hbm.h +8 -0
  60. data/ext/ggml/src/ggml-cpu/ggml-cpu-impl.h +386 -0
  61. data/ext/ggml/src/ggml-cpu/ggml-cpu-quants.c +10835 -0
  62. data/ext/ggml/src/ggml-cpu/ggml-cpu-quants.h +63 -0
  63. data/ext/ggml/src/ggml-cpu/ggml-cpu-traits.cpp +36 -0
  64. data/ext/ggml/src/ggml-cpu/ggml-cpu-traits.h +38 -0
  65. data/ext/ggml/src/ggml-cpu/ggml-cpu.c +14123 -0
  66. data/ext/ggml/src/ggml-cpu/ggml-cpu.cpp +622 -0
  67. data/ext/ggml/src/ggml-cpu/llamafile/sgemm.cpp +1884 -0
  68. data/ext/ggml/src/ggml-cpu/llamafile/sgemm.h +14 -0
  69. data/ext/ggml/src/ggml-cuda/vendors/cuda.h +14 -0
  70. data/ext/ggml/src/ggml-cuda/vendors/hip.h +186 -0
  71. data/ext/ggml/src/ggml-cuda/vendors/musa.h +134 -0
  72. data/ext/ggml/src/ggml-impl.h +556 -0
  73. data/ext/ggml/src/ggml-kompute/ggml-kompute.cpp +2251 -0
  74. data/ext/ggml/src/ggml-metal/ggml-metal-impl.h +288 -0
  75. data/ext/ggml/src/ggml-metal/ggml-metal.m +4884 -0
  76. data/ext/ggml/src/ggml-metal/ggml-metal.metal +6732 -0
  77. data/ext/ggml/src/ggml-opt.cpp +854 -0
  78. data/ext/ggml/src/ggml-quants.c +5238 -0
  79. data/ext/ggml/src/ggml-quants.h +100 -0
  80. data/ext/ggml/src/ggml-rpc/ggml-rpc.cpp +1406 -0
  81. data/ext/ggml/src/ggml-sycl/common.cpp +95 -0
  82. data/ext/ggml/src/ggml-sycl/concat.cpp +196 -0
  83. data/ext/ggml/src/ggml-sycl/conv.cpp +99 -0
  84. data/ext/ggml/src/ggml-sycl/convert.cpp +547 -0
  85. data/ext/ggml/src/ggml-sycl/dmmv.cpp +1023 -0
  86. data/ext/ggml/src/ggml-sycl/element_wise.cpp +1030 -0
  87. data/ext/ggml/src/ggml-sycl/ggml-sycl.cpp +4729 -0
  88. data/ext/ggml/src/ggml-sycl/im2col.cpp +126 -0
  89. data/ext/ggml/src/ggml-sycl/mmq.cpp +3031 -0
  90. data/ext/ggml/src/ggml-sycl/mmvq.cpp +1015 -0
  91. data/ext/ggml/src/ggml-sycl/norm.cpp +378 -0
  92. data/ext/ggml/src/ggml-sycl/outprod.cpp +56 -0
  93. data/ext/ggml/src/ggml-sycl/rope.cpp +276 -0
  94. data/ext/ggml/src/ggml-sycl/softmax.cpp +251 -0
  95. data/ext/ggml/src/ggml-sycl/tsembd.cpp +72 -0
  96. data/ext/ggml/src/ggml-sycl/wkv6.cpp +141 -0
  97. data/ext/ggml/src/ggml-threading.cpp +12 -0
  98. data/ext/ggml/src/ggml-threading.h +14 -0
  99. data/ext/ggml/src/ggml-vulkan/ggml-vulkan.cpp +8657 -0
  100. data/ext/ggml/src/ggml-vulkan/vulkan-shaders/vulkan-shaders-gen.cpp +593 -0
  101. data/ext/ggml/src/ggml.c +7694 -0
  102. data/ext/include/whisper.h +672 -0
  103. data/ext/metal-embed.mk +17 -0
  104. data/ext/metal.mk +6 -0
  105. data/ext/ruby_whisper.cpp +1608 -159
  106. data/ext/ruby_whisper.h +10 -0
  107. data/ext/scripts/get-flags.mk +38 -0
  108. data/ext/src/coreml/whisper-decoder-impl.h +146 -0
  109. data/ext/src/coreml/whisper-decoder-impl.m +201 -0
  110. data/ext/src/coreml/whisper-encoder-impl.h +142 -0
  111. data/ext/src/coreml/whisper-encoder-impl.m +197 -0
  112. data/ext/src/coreml/whisper-encoder.h +26 -0
  113. data/ext/src/openvino/whisper-openvino-encoder.cpp +108 -0
  114. data/ext/src/openvino/whisper-openvino-encoder.h +31 -0
  115. data/ext/src/whisper.cpp +7393 -0
  116. data/extsources.rb +6 -0
  117. data/lib/whisper/model/uri.rb +157 -0
  118. data/lib/whisper.rb +2 -0
  119. data/tests/helper.rb +7 -0
  120. data/tests/jfk_reader/.gitignore +5 -0
  121. data/tests/jfk_reader/extconf.rb +3 -0
  122. data/tests/jfk_reader/jfk_reader.c +68 -0
  123. data/tests/test_callback.rb +160 -0
  124. data/tests/test_error.rb +20 -0
  125. data/tests/test_model.rb +71 -0
  126. data/tests/test_package.rb +31 -0
  127. data/tests/test_params.rb +160 -0
  128. data/tests/test_segment.rb +83 -0
  129. data/tests/test_whisper.rb +211 -123
  130. data/whispercpp.gemspec +36 -0
  131. metadata +137 -11
  132. data/ext/ggml.c +0 -8616
  133. data/ext/ggml.h +0 -748
  134. data/ext/whisper.cpp +0 -4829
  135. data/ext/whisper.h +0 -402
data/Rakefile CHANGED
@@ -1,104 +1,64 @@
1
- require 'erb'
2
- require 'open3'
3
1
  require 'rake/clean'
4
- require 'rake/testtask'
5
- require 'rubygems/package'
6
-
7
- CLEAN.include '**/*.o'
8
- CLEAN.include "**/*.#{(defined?(RbConfig) ? RbConfig : Config)::MAKEFILE_CONFIG['DLEXT']}"
9
- CLOBBER.include 'doc'
10
- CLOBBER.include '**/*.log'
11
- CLOBBER.include '**/Makefile'
12
- CLOBBER.include '**/extconf.h'
13
- CLOBBER.include '**/extconf.h'
14
- CLOBBER.include '**/whisper.*'
15
- CLOBBER.include '**/ggml.*'
16
- CLOBBER.include '**/dr_wav.h'
17
-
18
- BUILD_VERSION=2
19
- # Determine the current version of the software
20
- if File.read('../../CMakeLists.txt') =~ /project.*\s*VERSION\s*(\d.+)\)/
21
- CURRENT_VERSION = "#{$1}.#{BUILD_VERSION}"
22
- else
23
- CURRENT_VERSION = "0.0.0.#{BUILD_VERSION}"
2
+ require "bundler/gem_tasks"
3
+ require "rake/testtask"
4
+ require_relative "extsources"
5
+
6
+ SOURCES = FileList[]
7
+
8
+ EXTSOURCES.each do |src|
9
+ basename = src.pathmap("%f")
10
+ dest = basename == "LICENSE" ? basename : src.pathmap("%{../..,ext}p")
11
+ dir = dest.pathmap("%d")
12
+ file src
13
+ directory dir
14
+ file dest => [src, dir] do |t|
15
+ cp t.source, t.name
16
+ end
17
+ SOURCES.include dest
24
18
  end
25
19
 
26
- def shell(args, opts = {})
27
- puts "> #{args.join(' ')}"
28
- cmd, live_stream, cwd = args, opts[:live_stdout], opts[:cwd]
29
- Dir.chdir(cwd) {
30
- wait_thr = nil
20
+ CLEAN.include SOURCES
21
+ CLEAN.include FileList["ext/*.o", "ext/*.metal", "ext/whisper.{so,bundle,dll}"]
31
22
 
32
- Open3.popen3(*cmd) do |stdin, stdout, stderr, thr|
33
- stdin.close
34
- wait_thr = thr # Ruby 1.8 will not yield thr, this will be nil
23
+ task build: ["ext/Makefile", "ext/ruby_whisper.h", "ext/ruby_whisper.cpp", "whispercpp.gemspec"]
35
24
 
36
- while line = stdout.gets do
37
- live_stream.puts(line) if live_stream
38
- end
39
-
40
- while line = stderr.gets do
41
- puts line
42
- end
43
- end
44
-
45
- # prefer process handle directly from popen3, but if not available
46
- # fallback to global.
47
- p_status = wait_thr ? wait_thr.value : $?
48
- exit_code = p_status.exitstatus
49
- error = (exit_code != 0)
50
- }
51
- end
25
+ directory "pkg"
26
+ CLOBBER.include "pkg"
52
27
 
53
- make_program = (/mswin/ =~ RUBY_PLATFORM) ? 'nmake' : 'make'
54
- MAKECMD = ENV['MAKE_CMD'] || make_program
55
- MAKEOPTS = ENV['MAKE_OPTS'] || ''
56
- WHISPER_SO = "ext/whisper.#{(defined?(RbConfig) ? RbConfig : Config)::MAKEFILE_CONFIG['DLEXT']}"
28
+ LIB_NAME = "whisper".ext(RbConfig::CONFIG["DLEXT"])
29
+ SO_FILE = File.join("ext", LIB_NAME)
30
+ LIB_FILE = File.join("lib", LIB_NAME)
57
31
 
58
- file 'ext/Makefile' => 'ext/extconf.rb' do
59
- shell(['ruby', 'extconf.rb', ENV['EXTCONF_OPTS'].to_s],
60
- { live_stdout: STDOUT, cwd: "#{Dir.pwd}/ext" }
61
- )
32
+ file "ext/Makefile" => ["ext/extconf.rb", "ext/ruby_whisper.h", "ext/ruby_whisper.cpp"] + SOURCES do |t|
33
+ Dir.chdir "ext" do
34
+ ruby "extconf.rb"
35
+ end
62
36
  end
63
37
 
64
- def make(target = '')
65
- shell(["#{MAKECMD}", "#{MAKEOPTS}", "#{target}"].reject(&:empty?),
66
- { live_stdout: STDOUT, cwd: "#{Dir.pwd}/ext" }
67
- )
38
+ file SO_FILE => "ext/Makefile" do |t|
39
+ Dir.chdir "ext" do
40
+ sh "make"
41
+ end
68
42
  end
43
+ CLEAN.include SO_FILE
69
44
 
70
- # Let make handle dependencies between c/o/so - we'll just run it.
71
- file WHISPER_SO => (['ext/Makefile'] + Dir['ext/*.cpp'] + Dir['ext/*.c'] + Dir['ext/*.h']) do
72
- make
45
+ directory "lib"
46
+ file LIB_FILE => [SO_FILE, "lib"] do |t|
47
+ copy t.source, t.name
73
48
  end
49
+ CLEAN.include LIB_FILE
74
50
 
75
- desc "Compile the shared object"
76
- task :compile => [WHISPER_SO]
77
-
78
- desc "Default Task (Test project)"
79
- task :default => :test
80
-
81
- Rake::TestTask.new(:test) do |t|
82
- t.test_files = FileList['tests/test_*.rb']
83
- t.verbose = false
51
+ Rake::TestTask.new do |t|
52
+ t.test_files = FileList["tests/test_*.rb"]
84
53
  end
85
54
 
86
- desc 'Generate gem specification'
87
- task :gemspec do
88
- system("cp ../../LICENSE .")
89
- system("cp ../../README.md .")
90
- tspec = ERB.new(File.read(File.join(File.dirname(__FILE__),'lib','whispercpp.gemspec.erb')))
91
- File.open(File.join(File.dirname(__FILE__),'whispercpp.gemspec'),'wb') do|f|
92
- f << tspec.result
55
+ TEST_MEMORY_VIEW = "tests/jfk_reader/jfk_reader.#{RbConfig::CONFIG['DLEXT']}"
56
+ file TEST_MEMORY_VIEW => "tests/jfk_reader/jfk_reader.c" do |t|
57
+ Dir.chdir "tests/jfk_reader" do
58
+ ruby "extconf.rb"
59
+ sh "make"
93
60
  end
94
61
  end
62
+ CLEAN.include "tests/jfk_reader/jfk_reader.{o,#{RbConfig::CONFIG['DLEXT']}}"
95
63
 
96
- desc 'Build gem'
97
- task :package => :gemspec do
98
- spec_source = File.read File.join(File.dirname(__FILE__),'whispercpp.gemspec')
99
- spec = nil
100
- # see: http://gist.github.com/16215
101
- Thread.new { spec = eval("#{spec_source}") }.join
102
- spec.validate
103
- Gem::Package.build(spec)
104
- end
64
+ task test: [LIB_FILE, TEST_MEMORY_VIEW]
data/ext/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ Makefile
2
+ whisper.so
3
+ whisper.bundle
4
+ whisper.dll
5
+ scripts/get-flags.mk
6
+ *.o
7
+ *.c
8
+ *.cpp
9
+ *.h
10
+ *.m
11
+ *.metal
12
+ !ruby_whisper.cpp
13
+ !ruby_whisper.h
data/ext/cpu.mk ADDED
@@ -0,0 +1,9 @@
1
+ ggml/src/ggml-cpu/ggml-cpu-cpp.o: \
2
+ ggml/src/ggml-cpu/ggml-cpu.cpp \
3
+ ggml/include/ggml-backend.h \
4
+ ggml/include/ggml.h \
5
+ ggml/include/ggml-alloc.h \
6
+ ggml/src/ggml-backend-impl.h \
7
+ ggml/include/ggml-cpu.h \
8
+ ggml/src/ggml-impl.h
9
+ $(CXX) $(CXXFLAGS) -c $< -o $@