Skill Tracer
Skills › Scientific Agent Skills › hugging-science › using-models.md

using-models.md

129 lines · skills/hugging-science/references/using-models.md at 5f2bc03

Open on GitHub
1# Using scientific models from the catalog
2
3A Hub repository stores artifacts; it does not guarantee a Transformers loader or a
4hosted inference service. Read the model card, library, input alphabet, head, and
5license before choosing an execution path.
6
7| Path | Use when | Check first |
8|---|---|---|
9| Local Transformers | Architecture is supported, such as ESM2 | Matching tokenizer, pinned revision, memory and sequence length |
10| Author's native package | Model requires its own runtime, such as Evo2, STACK, TEDDY or AVEX | Author installation and preprocessing requirements |
11| Inference Providers | The exact model **and task** have a live provider mapping | Provider, permissions, quotas and billing |
12| Dedicated endpoint | A compatible model has already been deployed | Endpoint URL, deployed revision and task contract |
13| Space | A reviewed app exposes the required function | Runtime, SDK and current `view_api()` schema |
15Inference Providers includes `hf-inference`, the successor to the old serverless
16Inference API. A public model or Space is not a promise of free, available compute.

Using scientific models from the catalog

A Hub repository stores artifacts; it does not guarantee a Transformers loader or a hosted inference service. Read the model card, library, input alphabet, head, and license before choosing an execution path.

PathUse whenCheck first
Local TransformersArchitecture is supported, such as ESM2Matching tokenizer, pinned revision, memory and sequence length
Author's native packageModel requires its own runtime, such as Evo2, STACK, TEDDY or AVEXAuthor installation and preprocessing requirements
Inference ProvidersThe exact model and task have a live provider mappingProvider, permissions, quotas and billing
Dedicated endpointA compatible model has already been deployedEndpoint URL, deployed revision and task contract
SpaceA reviewed app exposes the required functionRuntime, SDK and current view_api() schema

Inference Providers includes hf-inference, the successor to the old serverless Inference API. A public model or Space is not a promise of free, available compute.

Raw lines 1 to 17
18## Local ESM2 embeddings
20The combined local workflow was tested with Python 3.13, Transformers 5.18.0,
21Torch 2.14.1, Datasets 5.0.1, Hub 1.33.0 and Gradio Client 2.7.1. Datasets 5.0.1
22requires `huggingface-hub<2`; installing every package's latest release together
23is incompatible. Use a separate project environment:
25```bash
26uv pip install 'transformers==5.18.0' 'torch==2.14.1' 'datasets==5.0.1' 'huggingface-hub==1.33.0' 'gradio-client==2.7.1' python-dotenv
27```
29The following pretrained download is illustrative; validation used a tiny random
30ESM2 model and local vocabulary, without downloading weights. It produces both
31per-residue and sequence embeddings, excluding BOS, EOS and padding. These are
32features, not calibrated mutation effects or folded structures.
34```python
35from dotenv import load_dotenv
36load_dotenv() # before importing Hub-dependent libraries
37import torch
38from transformers import AutoModel, AutoTokenizer
40model_id = "facebook/esm2_t12_35M_UR50D"
41revision = "6fbf070e65b0b7291e7bbcd451118c216cff79d8"
42tok = AutoTokenizer.from_pretrained(model_id, revision=revision)
43model = AutoModel.from_pretrained(model_id, revision=revision).eval()
44sequences = ["MKTAYIAKQR", "ACDE"]
45# Explicitly reject empty/invalid input; do not silently truncate residues.
46if any(not s or any(c not in "ACDEFGHIKLMNPQRSTVWYBXZUO" for c in s) for s in sequences):
47 raise ValueError("Expected nonempty uppercase protein sequences")
48if any(len(s) > 1022 for s in sequences):
49 raise ValueError("Choose an explicit long-sequence strategy before embedding")
50inputs = tok(sequences, padding=True, return_tensors="pt", return_special_tokens_mask=True)
51residue_mask = inputs.pop("special_tokens_mask").eq(0) & inputs["attention_mask"].bool()
52with torch.inference_mode():
53 hidden = model(**inputs).last_hidden_state
54per_residue = [h[m] for h, m in zip(hidden, residue_mask)]
55mean_embeddings = torch.stack([h.mean(dim=0) for h in per_residue])
56assert [len(h) for h in per_residue] == [len(s) for s in sequences]
57```
59ESM2 is a masked language model. Sequence generation, variant scoring and
60folding require different heads/procedures; `AutoModel` embeddings alone do not
61perform those tasks. For downstream evaluation, split by protein family or
62homology clusters when relevant, rather than allowing close homologs across folds.

Local ESM2 embeddings

The combined local workflow was tested with Python 3.13, Transformers 5.18.0, Torch 2.14.1, Datasets 5.0.1, Hub 1.33.0 and Gradio Client 2.7.1. Datasets 5.0.1 requires huggingface-hub<2; installing every package's latest release together is incompatible. Use a separate project environment:

uv pip install 'transformers==5.18.0' 'torch==2.14.1' 'datasets==5.0.1' 'huggingface-hub==1.33.0' 'gradio-client==2.7.1' python-dotenv

The following pretrained download is illustrative; validation used a tiny random ESM2 model and local vocabulary, without downloading weights. It produces both per-residue and sequence embeddings, excluding BOS, EOS and padding. These are features, not calibrated mutation effects or folded structures.

from dotenv import load_dotenv
load_dotenv()  # before importing Hub-dependent libraries
import torch
from transformers import AutoModel, AutoTokenizer

model_id = "facebook/esm2_t12_35M_UR50D"
revision = "6fbf070e65b0b7291e7bbcd451118c216cff79d8"
tok = AutoTokenizer.from_pretrained(model_id, revision=revision)
model = AutoModel.from_pretrained(model_id, revision=revision).eval()
sequences = ["MKTAYIAKQR", "ACDE"]
# Explicitly reject empty/invalid input; do not silently truncate residues.
if any(not s or any(c not in "ACDEFGHIKLMNPQRSTVWYBXZUO" for c in s) for s in sequences):
    raise ValueError("Expected nonempty uppercase protein sequences")
if any(len(s) > 1022 for s in sequences):
    raise ValueError("Choose an explicit long-sequence strategy before embedding")
inputs = tok(sequences, padding=True, return_tensors="pt", return_special_tokens_mask=True)
residue_mask = inputs.pop("special_tokens_mask").eq(0) & inputs["attention_mask"].bool()
with torch.inference_mode():
    hidden = model(**inputs).last_hidden_state
per_residue = [h[m] for h, m in zip(hidden, residue_mask)]
mean_embeddings = torch.stack([h.mean(dim=0) for h in per_residue])
assert [len(h) for h in per_residue] == [len(s) for s in sequences]

ESM2 is a masked language model. Sequence generation, variant scoring and folding require different heads/procedures; AutoModel embeddings alone do not perform those tasks. For downstream evaluation, split by protein family or homology clusters when relevant, rather than allowing close homologs across folds.

Raw lines 18 to 63
64## Native scientific runtimes and custom code
66Evo2 uses `from evo2 import Evo2` and its own tokenizer/Vortex runtime. The Arc
67repositories are **not** drop-in `AutoModel`/`AutoTokenizer` checkpoints. The
68current author instructions distinguish 7B BF16 models from 1B/20B/40B models
69requiring FP8/Transformer Engine and Hopper hardware; 40B needs multiple H100s.
70Follow the [Evo2 source instructions](https://github.com/ArcInstitute/evo2),
71including their numerical checks. No Evo2 runtime was installed for this review.
73Some other Hub architectures require `trust_remote_code=True`; use it only when
74the selected card actually requires it, after reviewing the named repository and
75pinning the code revision. It executes repository Python. Existing task authorization
76may cover that execution; otherwise obtain authorization before running it. Being
77listed in the catalog does not establish code safety or scientific validity.
79Memory estimates must include weights, dtype, activations, batch size, sequence
80length and framework overhead. Two bytes per parameter estimates FP16/BF16 weights
81only. A parameter-count threshold or fixed training multiplier cannot guarantee
82that a scientific model fits or is numerically supported on a particular GPU.

Native scientific runtimes and custom code

Evo2 uses from evo2 import Evo2 and its own tokenizer/Vortex runtime. The Arc repositories are not drop-in AutoModel/AutoTokenizer checkpoints. The current author instructions distinguish 7B BF16 models from 1B/20B/40B models requiring FP8/Transformer Engine and Hopper hardware; 40B needs multiple H100s. Follow the Evo2 source instructions, including their numerical checks. No Evo2 runtime was installed for this review.

Some other Hub architectures require trust_remote_code=True; use it only when the selected card actually requires it, after reviewing the named repository and pinning the code revision. It executes repository Python. Existing task authorization may cover that execution; otherwise obtain authorization before running it. Being listed in the catalog does not establish code safety or scientific validity.

Memory estimates must include weights, dtype, activations, batch size, sequence length and framework overhead. Two bytes per parameter estimates FP16/BF16 weights only. A parameter-count threshold or fixed training multiplier cannot guarantee that a scientific model fits or is numerically supported on a particular GPU.

Raw lines 64 to 83
84## Check hosting before using InferenceClient
86This metadata-only example is publicly executable and downloads no weights:
88```python
89from huggingface_hub import HfApi
90model_id = "facebook/esm2_t33_650M_UR50D"
91info = HfApi(token=False).model_info(model_id, expand=["inferenceProviderMapping"])
92mapping = info.inference_provider_mapping or []
93live = {route.provider: route for route in mapping if route.status == "live"}
94print({name: route.task for name, route in live.items()})
95```
97On 2026-10-01 the ESM2 repository mapped to `hf-inference` for **fill-mask**,
98not feature extraction. `arcinstitute/evo2_40b` had an empty mapping; do not route
99it to Together or infer availability from its size. Mappings change; check again
100at execution time. Arc documents a separate NVIDIA hosted option.
102Illustrative authenticated inference, **not executed in this review**:
104```python
105import os
106from dotenv import load_dotenv
107load_dotenv()
108from huggingface_hub import InferenceClient
110# First confirm the live mapping above still supports this exact task.
111with InferenceClient(provider="hf-inference", model=model_id,
112 token=os.environ["HF_TOKEN"], timeout=60) as client:
113 candidates = client.fill_mask("MKT<mask>YIAKQR")
114for candidate in candidates:
115 print(candidate.token_str, candidate.score)
116```
118The client routes the task request and parses a list of fill-mask result objects.
119These scores describe masked-token probabilities, not experimental activity.
120For other tasks use their documented input/return contracts; `text_generation`
121is not a generic interface for DNA models. `HF_TOKEN` is used for HF-routed
122requests; a provider's own key uses that provider's direct billing. Check current
123permission and pricing requirements before a paid call. Dedicated endpoint URLs
124are an alternative to `provider`, not an additional provider selector.
126Sources: [ESM API](https://huggingface.co/docs/transformers/model_doc/esm),
127[Inference guide](https://huggingface.co/docs/huggingface_hub/guides/inference),
128[HfApi](https://huggingface.co/docs/huggingface_hub/package_reference/hf_api),
129[ESM2 card](https://huggingface.co/facebook/esm2_t12_35M_UR50D).

Check hosting before using InferenceClient

This metadata-only example is publicly executable and downloads no weights:

from huggingface_hub import HfApi
model_id = "facebook/esm2_t33_650M_UR50D"
info = HfApi(token=False).model_info(model_id, expand=["inferenceProviderMapping"])
mapping = info.inference_provider_mapping or []
live = {route.provider: route for route in mapping if route.status == "live"}
print({name: route.task for name, route in live.items()})

On 2026-10-01 the ESM2 repository mapped to hf-inference for fill-mask, not feature extraction. arcinstitute/evo2_40b had an empty mapping; do not route it to Together or infer availability from its size. Mappings change; check again at execution time. Arc documents a separate NVIDIA hosted option.

Illustrative authenticated inference, not executed in this review:

import os
from dotenv import load_dotenv
load_dotenv()
from huggingface_hub import InferenceClient

# First confirm the live mapping above still supports this exact task.
with InferenceClient(provider="hf-inference", model=model_id,
                     token=os.environ["HF_TOKEN"], timeout=60) as client:
    candidates = client.fill_mask("MKT<mask>YIAKQR")
for candidate in candidates:
    print(candidate.token_str, candidate.score)

The client routes the task request and parses a list of fill-mask result objects. These scores describe masked-token probabilities, not experimental activity. For other tasks use their documented input/return contracts; text_generation is not a generic interface for DNA models. HF_TOKEN is used for HF-routed requests; a provider's own key uses that provider's direct billing. Check current permission and pricing requirements before a paid call. Dedicated endpoint URLs are an alternative to provider, not an additional provider selector.

Sources: ESM API, Inference guide, HfApi, ESM2 card.

Raw lines 84 to 129