agentsclimarketplace

Pytorch model loading and forward pass

Skill HolobiomicsLab/asb-skill-collections/packs/metabolomics/gc-ms/skills/pytorch-model-loading-and-forward-pass

Use when when you have a pre-trained PyTorch model checkpoint (e.g., a MWFormer transformer) and structured input data (e.g., electron ionization mass spectrum m/z and intensity pairs) that must be converted to tensor format and passed through the model to produce a direct numerical output (e.From its SKILL.md

Install
npx -y skills add HolobiomicsLab/asb-skill-collections --skill pytorch-model-loading-and-forward-pass

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 15 stars15 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 file declares

Copied from the file, not written here

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

6.8 KB, ~1.1k tokens by cl100k_base, as published. Nobody here has run it

pytorch-model-loading-and-forward-pass

Summary

Load a pre-trained PyTorch transformer model and execute forward inference to generate predictions on structured input data. This skill bridges model artifact retrieval, tensor preparation, and model inference for end-to-end prediction workflows.

When to use

When you have a pre-trained PyTorch model checkpoint (e.g., a MWFormer transformer) and structured input data (e.g., electron ionization mass spectrum m/z and intensity pairs) that must be converted to tensor format and passed through the model to produce a direct numerical output (e.g., predicted molecular weight). Use this skill when inference is the goal and the model architecture and weights are already trained and frozen.

When NOT to use

  • Model requires retraining or fine-tuning on new data—use a training loop instead
  • Input spectrum is already embedded or pre-computed as features rather than raw m/z and intensity—use a simpler lookup or classifier
  • Model checkpoint is not available or has incompatible architecture version

Inputs

  • Pre-trained PyTorch model checkpoint (.pt or .pth file)
  • Electron ionization mass spectrum data (m/z values and intensity pairs)
  • Spectrum tensor formatted to model input shape (normalized, padded, or standardized)

Outputs

  • Predicted molecular weight (scalar or batch tensor)
  • Model output logits or confidence scores (if applicable)

How to apply

First, ensure the PyTorch environment (1.12 or compatible version) is active and dependencies are installed. Load the pre-trained model checkpoint from the repository using PyTorch's model loading utilities. Parse the input data (e.g., EI-MS spectrum with m/z and intensity values) and reshape it to match the model's expected tensor input format—this typically involves normalizing or padding the spectrum to a fixed size and converting to a torch.Tensor. Call the model's forward method (or call) with the prepared tensor as input, which triggers the transformer layers to generate the prediction. Extract and post-process the output (e.g., a scalar molecular weight prediction or logit vector) and record the result. The model operates in inference mode (no gradient computation), so wrap the forward pass in torch.no_grad() for efficiency.

Related tools

Evaluation signals

  • Output tensor shape and dtype match the documented model output specification (e.g., scalar float for MW prediction)
  • Predicted molecular weight value falls within chemically plausible range for the input spectrum mass range
  • Forward pass completes without gradient tracking (verified by torch.no_grad() context or model.eval() mode)
  • Predicted value is deterministic across multiple identical forward passes (no dropout or stochastic layers active in inference)
  • Input spectrum tensor has been correctly formatted to the model's expected input dimensions (e.g., batch × features × spectrum_length)

Limitations

  • Model performance depends on input spectrum quality and similarity to training data; EI-MS spectra from novel compounds or atypical ionization patterns may yield inaccurate predictions
  • Forward inference does not provide uncertainty estimates or confidence intervals unless the model outputs a distribution
  • Pre-trained checkpoint may not be compatible across different PyTorch versions or if model architecture code is not available
  • No changelog or version history available in the public repository, making it difficult to track model updates or retraining events

Evidence

  • [other] Load the pre-trained MWFormer model from the repository.: "4. Load the pre-trained MWFormer model from the repository."
  • [other] Parse the input EI-MS spectrum data (m/z and intensity values).: "5. Parse the input EI-MS spectrum data (m/z and intensity values)."
  • [other] Prepare the spectrum as a tensor input matching the model's expected input format.: "6. Prepare the spectrum as a tensor input matching the model's expected input format."
  • [other] Run forward inference through the MWFormer transformer to generate the predicted molecular weight.: "7. Run forward inference through the MWFormer transformer to generate the predicted molecular weight."
  • [other] The MWFormer model accepts electron ionization mass spectrum data as input and outputs a direct prediction of the molecular weight through a forward inference operation.: "The MWFormer model accepts electron ionization mass spectrum data as input and outputs a direct prediction of the molecular weight through a forward inference operation."
  • [readme] 2.Pytorch 1.12: "2.Pytorch 1.12"
  • [readme] Then refer to the example to use the model for prediction, and directly obtain the molecular weight from EI-MS.: "Then refer to the example to use the model for prediction, and directly obtain the molecular weight from EI-MS."

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.