Tensor shape validation and numerical correctness checking
Curated, evidence-grounded skill and software-tool collections for scientific AI agents, generated by the AgenticScienceBuilder
npx -y skills add HolobiomicsLab/asb-skill-collections --skill tensor-shape-validation-and-numerical-correctness-checkingAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 14 stars14 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
Use when after implementing a shared-weight ResNet18 encoder module but before integrating it into the DeepION data augmentation and projection workflow.
The file declares its own license as CC-BY-4.0. That is the author’s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.
SKILL.md
7.3 KB, ~1.2k tokens by cl100k_base, as published. Nobody here has run it
Tensor Shape Validation and Numerical Correctness Checking
License: restricted — no clear open-source license detected for the underlying tool; verify licensing before commercial use or redistribution. <!-- asb-license-banner -->
Summary
Verification step that confirms forward passes through a ResNet18-based encoder produce output tensors of expected shape (two 512-dimensional vectors) with numerically valid values before integration into the full DeepION contrastive learning pipeline. This prevents silent failures in representation learning that could compromise downstream ion image analysis.
When to use
After implementing a shared-weight ResNet18 encoder module but before integrating it into the DeepION data augmentation and projection workflow. Use this skill when you have instantiated encoder logic that takes two augmented ion images as input and must confirm the output dimensionality and numerical properties match the pipeline's expectations (512-dimensional representation vectors per image).
When NOT to use
- The encoder has not yet been instantiated or integrated into code; validation requires runnable forward logic.
- You are only reviewing architecture diagrams or pseudocode without executable model instances.
- The downstream task does not depend on exact dimensionality (though for DeepION, 512-dimensional vectors are essential to the projection and prediction modules).
Inputs
- Two augmented ion images (typically as PyTorch tensors or TensorFlow arrays)
- Instantiated ResNet18 encoder model with shared parameters
- Expected output dimensionality specification (512)
Outputs
- Boolean validation result (pass/fail) for shape correctness
- Boolean validation result for numerical validity (all finite values)
- Actual output tensor shapes and value ranges (for debugging)
How to apply
Execute forward passes of two augmented ion images through the instantiated shared ResNet18 encoder and inspect the resulting tensors. Verify that each forward pass produces a single 512-dimensional vector (expected output shape [1, 512] or [512] depending on batch handling). Check that output values are finite (no NaNs or infinities) and within a reasonable numerical range for learned representations. Use PyTorch or TensorFlow's built-in shape inspection (.shape attribute) and numerical validity checks (torch.isfinite(), tf.debugging.assert_all_finite()). Compare actual shapes against the documented 512-dimensional specification. If shapes or numerical properties deviate, debug encoder architecture (final fully connected layer configuration, batch normalization behavior) before proceeding to loss computation.
Related tools
- ResNet18 (Backbone encoder architecture modified to output 512-dimensional representation vectors from two augmented ion images) — https://github.com/gankLei-X/DeepION
- PyTorch (Deep learning framework for instantiating the encoder, executing forward passes, and inspecting tensor shapes and numerical properties)
- TensorFlow (Alternative deep learning framework for instantiating and validating the encoder (equivalent to PyTorch))
Examples
import torch
encoder = ResNet18(output_dim=512)
img1, img2 = torch.randn(1, 3, H, W), torch.randn(1, 3, H, W)
out1, out2 = encoder(img1), encoder(img2)
assert out1.shape == (1, 512) and out2.shape == (1, 512), f"Shape mismatch: {out1.shape}, {out2.shape}"
assert torch.isfinite(out1).all() and torch.isfinite(out2).all(), "NaN or Inf detected"
assert not torch.allclose(out1, out2), "Outputs are identical; check augmentation or encoder"
Evaluation signals
- Output tensor shape from each forward pass exactly matches [1, 512] or [batch_size, 512] depending on batch configuration; no dimension mismatch.
- All output tensor values are finite (no NaN, inf, or -inf);
torch.isfinite(output).all()or equivalent returns True. - Two distinct forward passes through the shared encoder on different augmented images produce different numerical vectors (no frozen or collapsed representations).
- Output vector magnitudes or statistics fall within expected ranges for initialized neural networks (e.g., not all zeros or all maximum float values).
- Integration into the projection and prediction modules (downstream in the pipeline) proceeds without dimension-related runtime errors.
Limitations
- Validation does not guarantee that the learned representations will be meaningful or that the contrastive loss will converge; it only confirms syntactic correctness.
- Shape validation is specific to the 512-dimensional specification for DeepION; other architectures or output dimensions require adjusted assertions.
- Numerical validity does not account for pathological cases such as gradient explosion or vanishing gradients during training, which may only manifest after multiple training iterations.
- Validation is performed on individual forward passes; it does not detect issues arising from parameter sharing semantics or backpropagation through shared weights.
Evidence
- [other] Verify that forward passes of two augmented images produce two distinct 512-dimensional representation vectors from the shared encoder.: "Verify that forward passes of two augmented images produce two distinct 512-dimensional representation vectors from the shared encoder."
- [other] Validate the output tensor shapes and numerical correctness before integration into the full DeepION pipeline.: "Validate the output tensor shapes and numerical correctness before integration into the full DeepION pipeline."
- [readme] Two augmented images are propagated through a pair of ResNet18-based encoders that shared parameters, then output two 512-dimensional representation vectors: "Two augmented images are propagated through a pair of ResNet18-based encoders that shared parameters, then output two 512-dimensional representation vectors"
- [other] Configure the encoder to output 512-dimensional vectors by modifying the final fully connected layer.: "Configure the encoder to output 512-dimensional vectors by modifying the final fully connected layer."
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.