Text Generation
Transformers
Safetensors
English
spin
tiny-models
custom-architecture
story-generation
experimental
custom_code
Run this model with HF Jobs
Run Quantech/spin-80k on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs and TRL to fine-tune https://huggingface.co/Quantech/spin-80k. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/Quantech/spin-80k on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Evaluate on a benchmark
Use HF Jobs to evaluate https://huggingface.co/Quantech/spin-80k. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.
Quantize for lower memory use
Use HF Jobs to create a 4-bit version of https://huggingface.co/Quantech/spin-80k. Push it to a new model repo, then reload it from there and report its memory footprint. Run `hf jobs --help` first to learn the CLI.
Instructions to use Quantech/spin-80k with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Quantech/spin-80k with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Quantech/spin-80k", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("Quantech/spin-80k", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Quantech/spin-80k with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Quantech/spin-80k" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Quantech/spin-80k", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/Quantech/spin-80k
- SGLang
How to use Quantech/spin-80k with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "Quantech/spin-80k" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Quantech/spin-80k", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "Quantech/spin-80k" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Quantech/spin-80k", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use Quantech/spin-80k with Docker Model Runner:
docker model run hf.co/Quantech/spin-80k
Update modeling_spin.py
Browse files5 unmodified lines6789101197 unmodified lines1091101111121131141153 unmodified lines11912012112212312412520 unmodified lines1461471481491501511521 unmodified line1541551561571581591601611621631641651661671681694 unmodified lines1741751761771781791801811821831841851861871881891905 unmodified linesfrom transformers.modeling_outputs import CausalLMOutputWithPastfrom .configuration_spin import SpinConfigclass RMSNorm(nn.Module):def __init__(self, dim: int, eps: float = 1e-5):97 unmodified linesclass SpinForCausalLM(PreTrainedModel, GenerationMixin):config_class = SpinConfig_tied_weights_keys = {"lm_head.weight": "tok_embeddings.weight"}_supports_cache_class = Falsedef __init__(self, config: SpinConfig):super().__init__(config)3 unmodified linesself.norm = RMSNorm(config.d_model, eps=config.norm_eps)self.lm_head = nn.Linear(config.d_model, config.vocab_size, bias=False)# Weight tyingself.lm_head.weight = self.tok_embeddings.weighthead_dim = config.d_model // config.n_heads20 unmodified linesinput_ids: torch.Tensor = None,attention_mask: torch.Tensor = None,labels: torch.Tensor = None,past_key_values: list = None,use_cache: bool = False,return_dict: bool = True,**kwargs,1 unmodified lineB, T = input_ids.shapex = self.tok_embeddings(input_ids)start_pos = 0if past_key_values is not None and len(past_key_values) > 0 and past_key_values[0] is not None:start_pos = past_key_values[0][0].shape[2]freqs_cos = self.freqs_cos[start_pos : start_pos + T]freqs_sin = self.freqs_sin[start_pos : start_pos + T]new_kv_caches = []for i, layer in enumerate(self.layers):cache_i = past_key_values[i] if past_key_values is not None else Nonex, new_cache = layer(x, freqs_cos, freqs_sin, kv_cache=cache_i)new_kv_caches.append(new_cache)4 unmodified linesif labels is not None:loss = F.cross_entropy(logits.view(-1, self.config.vocab_size), labels.view(-1), ignore_index=-100)if not return_dict:return (logits, loss, new_kv_caches)return CausalLMOutputWithPast(loss=loss,logits=logits,past_key_values=new_kv_caches if use_cache else None,)def prepare_inputs_for_generation(self, input_ids, past_key_values=None, attention_mask=None, **kwargs):if past_key_values is not None and len(past_key_values) > 0 and past_key_values[0] is not None:input_ids = input_ids[:, -1:]return {"input_ids": input_ids,5 unmodified lines6789101112131415161718192021222324252627282930313233343536373839404142434445464748495097 unmodified lines1481491501511521533 unmodified lines15715815916016116216320 unmodified lines1841851861871881891901 unmodified line1921931941951961971981992002012022032042054 unmodified lines2102112122132142152162172182192202212222232242252262272282292302312322332342352365 unmodified linesfrom transformers.modeling_outputs import CausalLMOutputWithPastfrom .configuration_spin import SpinConfigtry:from transformers.cache_utils import DynamicCacheHAVE_DYNAMIC_CACHE = Trueexcept ImportError:HAVE_DYNAMIC_CACHE = Falsedef extract_kv_cache(past_key_values):"""Safely extracts KV cache regardless of whether HF passes DynamicCache, list, or tuple."""if past_key_values is None:return None, 0# 1. Hugging Face DynamicCache / Cache objectif hasattr(past_key_values, "to_legacy_cache"):legacy = past_key_values.to_legacy_cache()seq_len = past_key_values.get_seq_length() if hasattr(past_key_values, "get_seq_length") else 0if seq_len == 0 or len(legacy) == 0:return None, 0return list(legacy), seq_lenif hasattr(past_key_values, "key_cache") and hasattr(past_key_values, "value_cache"):if len(past_key_values.key_cache) == 0:return None, 0kv_list = [(past_key_values.key_cache[i], past_key_values.value_cache[i])for i in range(len(past_key_values.key_cache))]seq_len = kv_list[0][0].shape[2] if len(kv_list) > 0 else 0return kv_list, seq_len# 2. Legacy tuple / list formatif isinstance(past_key_values, (list, tuple)) and len(past_key_values) > 0:if past_key_values[0] is None:return None, 0seq_len = past_key_values[0][0].shape[2]return list(past_key_values), seq_lenreturn None, 0class RMSNorm(nn.Module):def __init__(self, dim: int, eps: float = 1e-5):97 unmodified linesclass SpinForCausalLM(PreTrainedModel, GenerationMixin):config_class = SpinConfig_tied_weights_keys = {"lm_head.weight": "tok_embeddings.weight"}def __init__(self, config: SpinConfig):super().__init__(config)3 unmodified linesself.norm = RMSNorm(config.d_model, eps=config.norm_eps)self.lm_head = nn.Linear(config.d_model, config.vocab_size, bias=False)# Tie weightsself.lm_head.weight = self.tok_embeddings.weighthead_dim = config.d_model // config.n_heads20 unmodified linesinput_ids: torch.Tensor = None,attention_mask: torch.Tensor = None,labels: torch.Tensor = None,past_key_values=None,use_cache: bool = False,return_dict: bool = True,**kwargs,1 unmodified lineB, T = input_ids.shapex = self.tok_embeddings(input_ids)kv_caches_in, start_pos = extract_kv_cache(past_key_values)freqs_cos = self.freqs_cos[start_pos : start_pos + T]freqs_sin = self.freqs_sin[start_pos : start_pos + T]new_kv_caches = []for i, layer in enumerate(self.layers):cache_i = kv_caches_in[i] if kv_caches_in is not None else Nonex, new_cache = layer(x, freqs_cos, freqs_sin, kv_cache=cache_i)new_kv_caches.append(new_cache)4 unmodified linesif labels is not None:loss = F.cross_entropy(logits.view(-1, self.config.vocab_size), labels.view(-1), ignore_index=-100)# Package past_key_values back into HF expected formatif use_cache:if HAVE_DYNAMIC_CACHE and isinstance(past_key_values, DynamicCache):past_key_values_out = DynamicCache.from_legacy_cache(new_kv_caches)else:past_key_values_out = tuple(new_kv_caches)else:past_key_values_out = Noneif not return_dict:return (logits, loss, past_key_values_out)return CausalLMOutputWithPast(loss=loss,logits=logits,past_key_values=past_key_values_out,)def prepare_inputs_for_generation(self, input_ids, past_key_values=None, attention_mask=None, **kwargs):_, seq_len = extract_kv_cache(past_key_values)if seq_len > 0:input_ids = input_ids[:, -1:]return {"input_ids": input_ids,
modeling_spin.py+56-10