Views
No views yet
1from transformers import AutoModelForMaskedLM, AutoTokenizer
2import torch
3
4# Load with trust_remote_code=True
5model = AutoModelForMaskedLM.from_pretrained("mahdi-b/viral-esm2-3b-hqq", trust_remote_code=True)
6tokenizer = AutoTokenizer.from_pretrained("mahdi-b/viral-esm2-3b-hqq")
7
8# Use the model
9inputs = tokenizer("MSKGEELFTGVVPILVELDGDVNGHKFSVSGEGEGDATYGKLTLKFICTTGKLPVPWPTL", return_tensors="pt")
10inputs = {k: v.to(model.device) for k, v in inputs.items()}
11
12with torch.no_grad():
13 outputs = model(**inputs)1from transformers import AutoModelForMaskedLM, AutoTokenizer
2from hqq.models.hf.base import AutoHQQHFModel
3from hqq.core.quantize import BaseQuantizeConfig
4from huggingface_hub import hf_hub_download
5import torch
6
7# Download weights
8weights_path = hf_hub_download("mahdi-b/viral-esm2-3b-hqq", "pytorch_model.bin")
9
10# Create model with same quantization
11model = AutoModelForMaskedLM.from_pretrained("mahdi-b/viral-esm2-3b", torch_dtype=torch.float16)
12quant_cfg = BaseQuantizeConfig(nbits=4, group_size=16)
13AutoHQQHFModel.quantize_model(model, quant_config=quant_cfg, compute_dtype=torch.float16, device={"": torch.device("cuda:0")})
14
15# Load weights and move to GPU
16model.load_state_dict(torch.load(weights_path, map_location="cuda:0"))
17model = model.to("cuda:0")
18
19# Ready to use
20tokenizer = AutoTokenizer.from_pretrained("mahdi-b/viral-esm2-3b-hqq")