| ▲ | smasher164 2 hours ago | |
I guess I interpreted this part of their README as implying that the author found RC too fragile > Reference counting buys correctness and composability, but at a cost. > Disadvantage #1: you must balance every reference. Each value_create, value_retain, and each operation's implicit retain of its operands has to be matched by a value_release. Forget one and you leak; do one too many and you free memory that is still in use. The training examples in examples/ are verbose precisely because they are scrupulous about this in their error paths; that verbosity is the price of leak-free C. | ||
| ▲ | oraziorillo an hour ago | parent [-] | |
In general yes, but not if you are disciplined. I’d put it this way: though the idea of ref counting felt very natural at the beginning for my use case, at some point I realized there were probably better techniques to achieve the same goal. I found myself multiple times writing nonsense like: sum = value_add(v1, v2) mul = value_mul(sum, v3) [...] value_release(sum) value_release(mul) so that later I could release the sum. When you only have one intermediate value it’s still acceptable, but at 3-4 it starts getting cumbersome. After asking for feedback, someone rightfully pointed out that the better and faster approach for an autograd engine is using an arena allocator. My reason for saying “rightfully” is that arenas are ideal when you have many “objects” that have the same lifespan, such as the values involved in the forward/backward pass. RC is better when you have a lot of “objects” with independent lifespans. | ||