Repository navigation
FIX annotations on multi-output models, apply_pairwise without args, numpy input to characters and one_hot_to_fasta, plot_logo on non-ACGT characters, and the softmax rule under bf16 - #127
Merged
Conversation
The list of outputs was built by looping over the number of annotations instead of the number of model outputs. With one annotation on a two-output model only the first output came back, and with more annotations than outputs it raised IndexError. The test passed only because it used two annotations on a two-output model; it now runs one, two and three. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The same loop bound as in ablate_annotations: the list of outputs was built over the number of annotations instead of the number of model outputs, so one annotation on a two-output model returned one output and three annotations raised IndexError. The test now runs one, two and three annotations. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
args defaulted to None, but the pairing needs it: a call without args raised TypeError: 'NoneType' object is not iterable from inside the batching loop. args is now required, as in apply_product, so such a call fails at the call with the missing argument named. Calls that pass args are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Both take a numpy.ndarray by their signatures, but characters called .max(dim=0) on it and raised TypeError: _amax() got an unexpected keyword argument 'dim', and one_hot_to_fasta failed the same way through it. Both now convert an array to a tensor first, so one_hot_to_fasta also writes an all-zero column of an array as N, as it does for a tensor. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The default coloring covered only A, C, G and T, so a nonzero row for any other character of `alphabet`, such as N or an amino acid, raised KeyError. Those characters are now drawn gray. The custom-alphabet test drew nothing for its fifth character; it now does and checks the colors. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…plot_logo fixes Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 19, 2026
Merged
The rule computed in the dtype of the cached activations. Under dtype=torch.bfloat16 those are bf16, which holds the differences it divides to about three digits and cannot resolve its 1e-6 guards, so on ConvSoftmax the attributions differed from float32 by up to 0.021 on the CPU and 0.030 on CUDA, against attributions of at most 0.062. It now computes in at least float32, and the backward hook casts the multipliers back as before. The error falls to 2.2e-4 on the CPU and 2.7e-4 on CUDA, and to 1.6e-3 for a two-block transformer, from 1.6e-2. Float32 and float64 activations take the same path as before: .to() returns the tensor itself when the dtype already matches. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Six bugs on
main, each fixed in its own commit with a test that fails without the fix. All six predate #120. They came up while reviewing the test suite file by file. The existing tests used inputs, or tolerances, that hid them.Fixes
ablate_annotationsandmarginalize_annotationson models with several outputs. Both built their list of outputs withrange(len(y_befores)), which counts annotations rather than model outputs. On ConvDense, which has two outputs:IndexError: list index out of range.test_ablate_annotations_multiheadandtest_marginalize_annotations_multi_outputpassed only because they used two annotations. Both now run one, two and three annotations.apply_pairwiserequiredargsin practice but defaulted it toNone. Every call withoutargsraisedTypeError: 'NoneType' object is not iterablefrom inside the batching loop.argsis now a required parameter, as it is inapply_product. Calls that passargs(the tutorial, the skill and every test do) are unchanged.charactersandone_hot_to_fastaon numpy arrays. Both listnumpy.ndarrayin their signatures, butcharacterscalled.max(dim=0)on the array and raisedTypeError: _amax() got an unexpected keyword argument 'dim'.one_hot_to_fastafailed the same way throughcharacters. Both now convert an array to a tensor first, copying it only when it is not contiguous. As a result,one_hot_to_fastaalso writes the all-zero columns of an array as N, as it does for a tensor.plot_logoon alphabets with characters beyond A, C, G and T. The default colors covered only A, C, G and T. A nonzero row for any other character, such as N or an amino acid, raisedKeyError. Withcolor=None, such characters are now drawn gray. Acolordict that lacks a character still raises.test_plot_logo_alphabet_customleft its fifth row at zero, so it never drew N; it now draws it and checks the colors.The softmax rule of
deep_lift_shapandpisaunder bf16 autocast. The rule computed in the dtype of the cached activations, which is bf16 underdtype=torch.bfloat16.1e-6guards are below bf16's resolution._b_hookcasts the multipliers back as before..to()returns the tensor itself when the dtype already matches.Largest difference from float32, before → after:
The existing autocast test compared only ConvPoolDense, to two decimals.
test_deep_lift_shap_autocast_softmax_matches_full_precisionchecks these four models: without the fix it fails in 7 of 8 cases, all except MultiHeadAttention on CUDA.Checks
sphinx -Wpasses.The six surfaces
charactersandone_hot_to_fastalistnumpy.ndarray.plot_logo'scolor=Noneentry says that other characters are drawn gray.ablateandproductsubsections are new.references/motif-effects.mdalready says that multi-output models return lists.references/product.mdandreferences/func-pattern.mdalways passargs.🤖 Generated with Claude Code