Conversation
Codecov Report✅ All modified and coverable lines are covered by tests.
🚀 New features to boost your workflow:
|
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
Tbh I don't like it very much (because it's an extra function + some cast is required) but it's the only way to easily test that the correct aggregators use the optimized _gramian_based method. I also tried using return type hint of TypeGuard[GramianWeightedAggergator] instead of bool for _can_skip_jacobian_combination, but it's not really correct since we also check that the aggregator has no forward hook, so that TypeGuard would be really weird. So in the end we have to use this cast.
|
See #524 (comment) for (a bit outdated) performance comparison. |
a48b0dd to
9d4c41c
Compare
|
With this PR, we rely a lot more on |
PierreQuinton
left a comment
There was a problem hiding this comment.
You can accept all commits together if you want, I prefer to use TypeGuards, it is prettier and clearer.
I think you missed one of my commit messages:
=> I asked claude if it was ok to use typeguard here, but it said that it should really only be used if the function only checks that the type of the aggregator is GramianWeightedAggergator. So i'd rather use cast just to be safe. |
|
I disagree with Claude here. The logic of typeguards is "if the check pass, then the type is A", not "the check passes if and only if the type is A". So here is is correct. Otherwise every function returning a typeguard would be exactly: def check_B(a: A) -> TypeGuard[B]:
return isinstance(a, B)But of course if this was the only intended use of TypeGuards, then they would have provided exactly this function instead. |
You're right. Please read this, it's short and very interesting: https://docs.python.org/3/library/typing.html#typing.TypeGuard Apparently there's also a So I think that:
Should we fire @claude? |
|
Claude finished @ValerianRey's task in 52s —— View job Analysis of TypeGuard vs TypeIsYou're absolutely right, and I apologize for my earlier incorrect guidance! Let me clarify the semantics: Todo List
TypeGuard vs TypeIs SemanticsTypeGuard:
TypeIs (Python 3.13+):
Analysis of Your Functions1.
|
|
Look at him trying to keep his 22$/month job. How pathetic. In all this noise he just said, he said something really important: TypeIs is only available since python 3.13. Let's use that in 3 years. (Technically, we could use the |
Co-authored-by: Pierre Quinton <pierre.quinton@epfl.ch>
for more information, see https://pre-commit.ci
|
Up-to-date time comparison between branch main (a55afca) and this (fc9bbcf) on CPU. Note that there is a bit of randomness in those results. Overall, I think it's better when jac_to_grad takes
I think that the most significant results are those of We have been quite lucky with the values obtained for the forward and backward for this PR, but we really could expect a -50 ms (out of 812 ms, so that's -6%) on Gaining 10% iteration speed (including forward, backward and jac_to_grad) just from this little change seems like a huge improvement IMO. Let's hope the results are similar on cuda (I'm scared that it could launch way too many cuda kernels and thus slow down things). I had a problem when profiling on cuda, so I need to investigate that. |
|
I just made a homemade memory visualizer because torch doesn't provide any for CPU and the one for GPU is broken.
=> It seems that we do half peak memory usage. Really nice. On the blue line, the jump from ~0.7 to ~1.41 corresponds to the memory allocation of |
|
The The plots are extremely cool, we should put one in the release notes eventually. |
|
Following our discussion where we considered making the Generics |
|
CUDA Traces Comparison
=> This seems too slow on cuda. I think we can't merge this until we have a way to parallelize the cuda kernel launches or whetever it is that takes this extra time. |















Avoid concatenation of the jacobians when the aggregator is gramian-based. Also use a deque to free each jacobian as soon as it is used.