-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect derivative result when nested void functions and recursive nature functions are used. #1809
Comments
Hi @stebos100 yeah a full file that we can run to reproduce would be helpful here (and ideally an enzyme.mit.edu/explorer link) . |
And yes Enzyme can deal with intermediate functions which return void, as well as recursive functions -- so seeing the full case and expected results would be helpful. It would be also helpful to know what version of Enzyme and LLVM you are using. |
Hi @wsmoses , thanks for checking up, I have altered the script slightly to get the point across. I am using LLVM v16, and Enzyme v0.0.103. It seems that when I use a recursive function within a void function Enzyme produces the incorrect derivative result. And when we perform the same function body on CPU vs GPU different results are produced. Please see the script below and please feel free to ask any questions if they are needed.
|
Ah since you're on GPU my guess is that you may run out of device memory for the caches (and cuda throw an error not being caught). To reduce unnecessary caching can you add restrict on all pointers arguments of the function you're autodiffing (assuming that they point to different locations in memory)? If that doen't resolve I'll take a closer look and find a GPU machine to test on. |
HI @wsmoses, even after adding the restrict qualifier it produces the incorrect derivative result on the GPU when compared to the CPU example. Both the CPU and GPU results however do not accommodate the first issue (calling the void recursive function), which I believe is also an important issue to address. I have a GPU handy, so if needs be I could always try and run test scripts for you if needed. Thanks so much again ! |
Hi @wsmoses, I was just wondering if you managed to see the above ? It seems that in a simulation setting, Enzyme is not able to produce the correct derivative results. I believe that the issue is that the recursive nature of the function ie gbm[4] = gbm[3] * ... and gbm[3] comprises of gbm[2]... and gbm[2] = gbm[1]..... Therefore gbm[3] should have derivatives for gbm[2] & gbm[1]. and for gbm[4] should have derivatives for gbm[3], gbm[2], gbm[1]. therefore for each new iteration gbm[N], there are derivatives for the gbm[N -1-> 0] elements. |
I have recently been running an experiment testing some of the limitations associated with using Enzyme and have found the following interesting case and was wondering if anyone could help me or if applicable be added as an issue. When running a function that uses nested void functions, as shown in the script below, the incorrect derivative result is produced when compared to the finite difference approximation result.
1.) Can Enzyme accommodate nested functions containing void functions ? It seems that it cannot.
2.) The second limiting case I found is that when a function uses a recursive function shown in the script below, Enzyme produces the wrong derivative result when compared to the finite difference approximation, is there a way around this ?
More specifically it seems that the [i-1] indexing may be the underlying issue here
Thanks again everyone, please let me know if you would like the accompanying enzyme calls from main.
The text was updated successfully, but these errors were encountered: