Repository navigation
Conversation
Use filesystem to check if a file exists before calling `sf_open`. Calling `sf_open` on a missing file sends output to std::cerr, and this helps us avoid that.
…eader::checkFile.
NB. some liberties are taken with expressions whose derivatives aren't always well-defined, e.g. modulo.
|
Thanks for the PR. I had a small conflict but it should be OK. Testing a bit before merge. |
Thanks Stéphane. Yeah, I tried to resolve some conflicts via the interface here, but I must've overlooked something. |
|
SignalAutoDifferentiate was duplicated in sigPromotion.hh. Just pushed a fix. |
|
Got: |
|
Oh, is |
|
Where is |
|
On the (linux) machine I'm working on it lives in math.h, line 1129. |
|
Seems not standard, then better provide a custom defined version. |
|
Thanks. |
|
Finally rebased in master-dev branch and merged in 681a303, thanks! |
|
Hi there I am Puja Kumari currently planning to contribute to open source through GSOC and I found the GRAME community quite intresting because primarily focusing on projects related to audio programming and digital signal processing. |
|
Hi @Pujakumari1202, take a look at the Faust Ideas repository; read the links in the readme there, and consider joining the Discord server (https://discord.gg/RzuFg6B8zA). |
|
I have joined Discord, but this is my first time, and i have no idea what to do next or how to proceed, but we really want to do this. |
Google Summer of Code: Automatic Differentiation in the Faust Compiler
The goal of this project was to add automatic differentiation functionality to the Faust compiler as a signal stage transformation, and create a Faust architecture file for carrying out gradient descent based on automatically differentiated Faust DSP instances.
Support for differentiable Faust algorithms would facilitate gradient computation, suitable for application in machine learning problems, for all available Faust backends.
Deliverables
The following headline contributions have been made:
SignalAutoDifferentiateclass and, for math.h-equivalent primitives, descendents of thextendedclass.autodiff.cpp, compilable to an executable for computing gradient descent..dspfiles for exploring and testing autodiff functionality and gradient descent.autodiff.shfor streamlining the process of building the gradient descent application, executing it with suitable example files, and plotting the results.autodiffVerifier.cpp, compilable to an executable for assessing the validity of automatically differentiated Faust programs via comparison with differentiation by finite differences.Usage
The autodiff architecture file uses libfaust to compile DSP algorithms dynamically at runtime, so Faust must be compiled and installed with the LLVM backend:
cd build make BACKENDS=all.cmake TARGETS=all.cmake sudo make installBuilding and running an autodiff example
Rather than using the Faust compiler with the
-aflag, the autodiff architecture file should be compiled directly, andllvm-configused to generate the appropriate compiler flags:The compiled executable can then be run, with input (
--input), ground truth (--gt) and differentiable (--diff) DSP files specified, plus optional loss function (-lf) and learning rate (-lr):Output is a tabular representation of per-iteration loss and parameter values. For instance, for the
one_zerofilter example, with a single learnable parameterb1:The executable also generates a csv file containing this data; the data can be plotted with the script
plot.py.The above commands are encapsulated in the shell script
autodiff.sh.Verification via finite differences
Compile
autodiffVerifier.cppto produce an executable for comparing the output of an autodiffed algorithm with that of the same algorithm differentiated by way of finite differences:Run the executable, specifying input and differentiable
.dspfiles, and the finite difference--epsilon:Output is the per-iteration delta between autodiffed and finite difference output:
Outstanding/Future work
The following tasks and aims remain for future work:
~;rdtableandrwtableprimitives;soundfileandwaveformprimitives;select2andselect3primitives;atan2math.h-equivalent primitive;The lack of a derivative expression for recursive expressions is a significant drawback, given the ubiquity of recursion in signal processing and audio synthesis algorithms. A mathematical expression for the derivative of a general-case recursive algorithm was devised, but implementing it at the signal stage proved to be beyond the reach of this body of work, and may not, in fact, be possible at the signal stage. Future work should focus on investigating whether realising autodiff as a box stage transformation instead will yield more favourable results. (Again, consult
architecture/autodiff/README.mdfor more information.)Given the absence of a derivative implementation for recursion, and much scope for improvement on what has been developed to date (in terms of loss calculation, etc.), this pull request is targeting the
auto-differentiatebranch rather thanmaster-dev. It is hoped that, with more work, autodiff and gradient descent may become core language features, and that the work represented by this pull request can be refined into something worthy of being merged into Faust's main development branch.Challenges, Reflections
In addition to the problem of recursion, which consumed at least a couple of weeks of doomed experimentation, I encountered a number of challenges along the way: