Closed hatchjaw closed 1 year ago
Thanks for the PR. I had a small conflict but it should be OK. Testing a bit before merge.
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:
/autodiff.sh gain
/usr/local/share/faust/autodiff/autodiff.cpp:221:28: error: use of undeclared identifier 'iszero'
gradient = iszero(delta) ?
^
1 error generated.
./autodiff.sh: line 62: ./my_autodiff: No such file or directory
Oh, is iszero
architecture/platform-specific?
Where is iszero
supposed to be defined ?
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 https://github.com/grame-cncm/faust/commit/681a303b8ddc9ef2e67c2cc5d5df83f27323b865, 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. It would be really great if the community members would help me to know regarding how should I get started.
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:
SignalAutoDifferentiate
class and, for math.h-equivalent primitives, descendents of thextended
class.autodiff.cpp
, compilable to an executable for computing gradient descent..dsp
files for exploring and testing autodiff functionality and gradient descent.autodiff.sh
for 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:
Building and running an autodiff example
Rather than using the Faust compiler with the
-a
flag, the autodiff architecture file should be compiled directly, andllvm-config
used 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_zero
filter 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.cpp
to 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
.dsp
files, 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:
~
;rdtable
andrwtable
primitives;soundfile
andwaveform
primitives;select2
andselect3
primitives;atan2
math.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.md
for 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-differentiate
branch 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: