bnosac / audio.whisper

Transcribe audio files using the "Whisper" Automatic Speech Recognition model from R
Other
113 stars 13 forks source link

incorporate compilation improvements #8

Closed jwijffels closed 1 year ago

jwijffels commented 1 year ago

https://github.com/ggerganov/whisper.cpp/blob/master/Makefile https://github.com/ggerganov/whisper.cpp/blob/master/CMakeLists.txt

jwijffels commented 1 year ago

Should write a configure script as the compilation flags for the speedups give warnings and might give crashes as well if these do not apply...

https://github.com/bnosac/audio.whisper/actions/runs/3767035657

── R CMD build ─────────────────────────────────────────────────────────────────
* checking for file ‘.../DESCRIPTION’ ... OK
* preparing ‘audio.whisper’:
* checking DESCRIPTION meta-information ... OK
* cleaning src
* checking for LF line-endings in source and make files and shell scripts
* checking for empty or unneeded directories
* building ‘audio.whisper_0.1.2.tar.gz’

── R CMD check ─────────────────────────────────────────────────────────────────
* using log directory ‘/home/runner/work/audio.whisper/audio.whisper/check/audio.whisper.Rcheck’
* using R Under development (unstable) (2022-12-21 r83491)
* using platform: x86_64-pc-linux-gnu (64-bit)
* R was compiled by
    gcc (Ubuntu 11.2.0-19ubuntu1) 11.2.0
    GNU Fortran (Ubuntu 11.2.0-19ubuntu1) 11.2.0
* using session charset: UTF-8
* using C++ compiler: ‘g++ (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0’
* using options ‘--no-manual --as-cran’
* checking for file ‘audio.whisper/DESCRIPTION’ ... OK
* checking extension type ... Package
* this is package ‘audio.whisper’ version ‘0.1.2’
* package encoding: UTF-8
* checking package namespace information ... OK
* checking package dependencies ... OK
* checking if this is a source package ... OK
* checking if there is a namespace ... OK
* checking for executable files ... OK
* checking for hidden files and directories ... OK
* checking for portable file names ... OK
* checking for sufficient/correct file permissions ... OK
* checking serialization versions ... OK
* checking whether package ‘audio.whisper’ can be installed ... [71s/72s] OK
* checking installed package size ... NOTE
  installed size is 13.1Mb
  sub-directories of 1Mb or more:
    libs     7.5Mb
    models   5.0Mb
* checking package directory ... OK
* checking for future file timestamps ... OK
* checking DESCRIPTION meta-information ... OK
* checking top-level files ... OK
* checking for left-over files ... OK
* checking index information ... OK
* checking package subdirectories ... OK
* checking R files for non-ASCII characters ... OK
* checking R files for syntax errors ... OK
* checking whether the package can be loaded ... OK
* checking whether the package can be loaded with stated dependencies ... OK
* checking whether the package can be unloaded cleanly ... OK
* checking whether the namespace can be loaded with stated dependencies ... OK
* checking whether the namespace can be unloaded cleanly ... OK
* checking loading without being on the library search path ... OK
* checking dependencies in R code ... OK
* checking S3 generic/method consistency ... OK
* checking replacement functions ... OK
* checking foreign function calls ... OK
* checking R code for possible problems ... OK
* checking Rd files ... OK
* checking Rd metadata ... OK
* checking Rd line widths ... OK
* checking Rd cross-references ... OK
* checking for missing documentation entries ... OK
* checking for code/documentation mismatches ... OK
* checking Rd \usage sections ... OK
* checking Rd contents ... OK
* checking for unstated dependencies in examples ... OK
* checking line endings in C/C++/Fortran sources/headers ... OK
* checking line endings in Makefiles ... OK
* checking compilation flags in Makevars ... WARNING
Warning: Non-portable flags in variable 'PKG_CFLAGS':
  -mavx -mavx2 -mfma -mf16c
* checking for GNU extensions in Makefiles ... OK
* checking for portable use of $(BLAS_LIBS) and $(LAPACK_LIBS) ... OK
* checking use of PKG_*FLAGS in Makefiles ... OK
* checking use of SHLIB_OPENMP_*FLAGS in Makefiles ... OK
* checking pragmas in C/C++ headers and code ... OK
* checking compilation flags used ... NOTE
Compilation used the following non-portable flag(s):
  ‘-mavx’ ‘-mavx2’ ‘-mf16c’ ‘-mfma’
* checking compiled code ... OK
* checking examples ... OK
* checking for unstated dependencies in ‘tests’ ... OK
* checking tests ...
  Running ‘tinytest.R’ [15s/16s]
 [16s/17s] OK
* checking for non-standard things in the check directory ... OK
* checking for detritus in the temp directory ... OK
* DONE
Status: 1 WARNING, 2 NOTEs
See
  ‘/home/runner/work/audio.whisper/audio.whisper/check/audio.whisper.Rcheck/00check.log’
for details.

── R CMD check results ──────────────────────────────── audio.whisper 0.1.2 ────
Duration: 1m [44](https://github.com/bnosac/audio.whisper/actions/runs/3767035657/jobs/6404170180#step:6:46).8s

❯ checking compilation flags in Makevars ... WARNING
  Non-portable flags in variable 'PKG_CFLAGS':
    -mavx -mavx2 -mfma -mf16c

❯ checking installed package size ... NOTE
    installed size is 13.1Mb
    sub-directories of 1Mb or more:
      libs     7.5Mb
      models   5.0Mb

❯ checking compilation flags used ... NOTE
  Compilation used the following non-portable flag(s):
    ‘-mavx’ ‘-mavx2’ ‘-mf16c’ ‘-mfma’

0 errors ✔ | 1 warning ✖ | 2 notes ✖
Error: Error: R CMD check found WARNINGs
jwijffels commented 1 year ago

Hello @jeroen

My apologies to tag you in this. Feel free to disregard if you are not interested to help.

I'm looking to make this R package (which allows to transcribe audio files - examples in the readme at https://github.com/bnosac/audio.whisper) CRAN compliant - if at all possible. It is an Rcpp wrapper around whisper.cpp which allows to transcribe audio files.

whisper.cpp has some large speedup improvements by setting compilation flags as can be seen at https://github.com/ggerganov/whisper.cpp/blob/master/Makefile This is done by basically setting the compilation flags -mavx -mavx2 -mfma -mf16c -msse3 if the hardware allows. This goes beyond my compiler skills in order to set this good for CRAN. Do you know of a way to do this? Many thanks!

jeroen commented 1 year ago

Basically CRAN does not allow this, because it is considered non-portable (because it won't work on hardware that does not have those extensions). So at best you can make it opt-in for users that compile from source...

jwijffels commented 1 year ago

Thanks. That's what I thought.

So at best you can make it opt-in for users that compile from source...

Would you happen to have a pointer to a configure script which does similar things?

jeroen commented 1 year ago

I think you can just add something like this (not tested) to your Makevars:

ifdef USE_HARDWARE_EXT
PKG_CFLAGS = -mavx -mavx2 -mfma -mf16c
endif

And then users can set an environment variable USE_HARDWARE_EXT before they install from source

jwijffels commented 1 year ago

Many thanks. I´ll try that out!

jwijffels commented 1 year ago

Yes that seems to do it. :rocket: