Finetuner performance + robustness optimizations#11
Open
r-kellerm wants to merge 1 commit into
Open
Conversation
r-kellerm
commented
Jun 11, 2026
- AMP for the full fine-tune path - added use_amp/amp_dtype args plus _is_cuda_device/_amp_available/_pick_amp_dtype helpers and a _autocast() context. Mixed precision is gated to amp_active = use_amp and not only_proj_layer, so the cached linear-probe path stays fp32 (avoids the bf16 to numpy cache crash). GradScaler is wired only for fp16; bf16 is preferred when supported and needs no scaling.
- zero_grad(set_to_none=True) - replaced plain zero_grad().
- Backbone freeze - on the probe path, backbone params are set requires_grad_(False) once and restored in a finally, replacing the per-batch no_grad()+detach().
- Robustness - avg_loss initialized to nan (no NameError on empty loader), and fwd_cache.clear() moved into the finally so the cache is released even on exceptions.
…_to_none=True) 3. Backbone freeze when only projection head is trained; + robustness changes - avg_loss initialized to nan and fwd_cache.clear() moved to finally block to run even in case of exceptions,
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.