Fix dtype upcast in removal-based ablation for discrete features#1170
Open
fbonc wants to merge 1 commit into
Open
Fix dtype upcast in removal-based ablation for discrete features#1170fbonc wants to merge 1 commit into
fbonc wants to merge 1 commit into
Conversation
The plain-tensor branch of RemovalBasedMetric._apply_ablation multiplied integer code-index inputs by a float mask (x * (1 - mask)), upcasting them to float. Downstream nn.Embedding then raised "Expected ... Long/Int but got FloatTensor", crashing comprehensiveness/ sufficiency evaluation on plain Transformer models. The tuple-input branch (e.g. StageNet) already handled this; the plain-tensor branch did not. Detect discrete (integer) inputs and zero-ablate them to the padding index with an integer-preserving (1 - mask).long() multiply. The dtype check, integer ablation, and the empty-row safety repair are extracted into a shared _apply_ablation_to_values helper so both input formats follow one path.
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.
Contributor: Felipe Amaral Bonchristiano (felipea5@illinois.edu)
Contribution Type: Fix dtype bug in base.py (metric-removal ablation)
Description
The plain-tensor branch of
RemovalBasedMetric._apply_ablation(inpyhealth/metrics/interpretability/base.py) ablates discrete code-index inputs by multiplying them with a float mask:This upcasts integer code indices to float. The downstream
nn.Embeddingthen raises:so
comprehensiveness/sufficiencyevaluation crashes for any plain-tensor (non-tuple) discrete input. e.g. a vanillaTransformer. The tuple-input branch (StageNet-style(time, values)) already guarded against this with a dtype check + integer-preserving multiply; the plain-tensor branch did not.Hit while building a MIMIC-IV-demo benchmark for the attention-rollout method (#1158). Running
evaluate_attributionwithcomprehensiveness/sufficiencyon a plainTransformertriggered the crash. This is a pre-existing bug independent of that PR.Fix
Detect discrete (integer) inputs and zero-ablate them to the padding index with
(1 - mask).long(), which preserves dtype. To avoid duplicating that logic across the tuple and plain-tensor branches, the dtype check, integer ablation, the continuous zero/mean/noise strategies, and the empty-row safety repair are extracted into a single shared_apply_ablation_to_valueshelper that both branches call. Behavior for continuous inputs is unchanged.Discrete features are always zero-ablated to the padding index regardless of
ablation_strategy(mean/noise are meaningless for categorical code indices); this is now documented in the helper.Files to review:
Base.py: bug fix