Instructions to use mgor/dual-stage-tossup-pipe with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use mgor/dual-stage-tossup-pipe with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="mgor/dual-stage-tossup-pipe") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("mgor/dual-stage-tossup-pipe") model = AutoModelForCausalLM.from_pretrained("mgor/dual-stage-tossup-pipe") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use mgor/dual-stage-tossup-pipe with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "mgor/dual-stage-tossup-pipe" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "mgor/dual-stage-tossup-pipe", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/mgor/dual-stage-tossup-pipe
- SGLang
How to use mgor/dual-stage-tossup-pipe 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 "mgor/dual-stage-tossup-pipe" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "mgor/dual-stage-tossup-pipe", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'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 "mgor/dual-stage-tossup-pipe" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "mgor/dual-stage-tossup-pipe", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use mgor/dual-stage-tossup-pipe with Docker Model Runner:
docker model run hf.co/mgor/dual-stage-tossup-pipe
Upload folder using huggingface_hub
Browse files- config.json +15 -0
- stage1/config.json +38 -0
- stage1/generation_config.json +6 -0
- stage1/merges.txt +0 -0
- stage1/model.safetensors +3 -0
- stage1/special_tokens_map.json +5 -0
- stage1/tokenizer.json +0 -0
- stage1/tokenizer_config.json +20 -0
- stage1/vocab.json +0 -0
- stage2/config.json +45 -0
- stage2/generation_config.json +6 -0
- stage2/merges.txt +0 -0
- stage2/model.safetensors +3 -0
- stage2/special_tokens_map.json +5 -0
- stage2/tokenizer.json +0 -0
- stage2/tokenizer_config.json +20 -0
- stage2/vocab.json +0 -0
- tiny_chained_tossup.py +80 -0
config.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"model_type": "gpt2",
|
| 3 |
+
"pipeline_tag": "text-generation",
|
| 4 |
+
"auto_map": {
|
| 5 |
+
"pipeline": "tiny_chained_tossup.QBChainedPipeline"
|
| 6 |
+
},
|
| 7 |
+
"custom_pipelines": {
|
| 8 |
+
"quizbowl-tossup": {
|
| 9 |
+
"impl": "tiny_chained_tossup.QBChainedPipeline",
|
| 10 |
+
"pt": [],
|
| 11 |
+
"tf": [],
|
| 12 |
+
"type": "text"
|
| 13 |
+
}
|
| 14 |
+
}
|
| 15 |
+
}
|
stage1/config.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"activation_function": "gelu_new",
|
| 3 |
+
"architectures": [
|
| 4 |
+
"GPT2LMHeadModel"
|
| 5 |
+
],
|
| 6 |
+
"attn_pdrop": 0.1,
|
| 7 |
+
"bos_token_id": 50256,
|
| 8 |
+
"embd_pdrop": 0.1,
|
| 9 |
+
"eos_token_id": 50256,
|
| 10 |
+
"initializer_range": 0.02,
|
| 11 |
+
"layer_norm_epsilon": 1e-05,
|
| 12 |
+
"model_type": "gpt2",
|
| 13 |
+
"n_ctx": 1024,
|
| 14 |
+
"n_embd": 768,
|
| 15 |
+
"n_head": 12,
|
| 16 |
+
"n_inner": null,
|
| 17 |
+
"n_layer": 12,
|
| 18 |
+
"n_positions": 1024,
|
| 19 |
+
"reorder_and_upcast_attn": false,
|
| 20 |
+
"resid_pdrop": 0.1,
|
| 21 |
+
"scale_attn_by_inverse_layer_idx": false,
|
| 22 |
+
"scale_attn_weights": true,
|
| 23 |
+
"summary_activation": null,
|
| 24 |
+
"summary_first_dropout": 0.1,
|
| 25 |
+
"summary_proj_to_labels": true,
|
| 26 |
+
"summary_type": "cls_index",
|
| 27 |
+
"summary_use_proj": true,
|
| 28 |
+
"task_specific_params": {
|
| 29 |
+
"text-generation": {
|
| 30 |
+
"do_sample": true,
|
| 31 |
+
"max_length": 50
|
| 32 |
+
}
|
| 33 |
+
},
|
| 34 |
+
"torch_dtype": "float32",
|
| 35 |
+
"transformers_version": "4.52.2",
|
| 36 |
+
"use_cache": true,
|
| 37 |
+
"vocab_size": 50257
|
| 38 |
+
}
|
stage1/generation_config.json
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_from_model_config": true,
|
| 3 |
+
"bos_token_id": 50256,
|
| 4 |
+
"eos_token_id": 50256,
|
| 5 |
+
"transformers_version": "4.52.2"
|
| 6 |
+
}
|
stage1/merges.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
stage1/model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c7d00560d8910fbed77ffad4065dee5011c41ba401b1064e749c498ba9e20373
|
| 3 |
+
size 497774208
|
stage1/special_tokens_map.json
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"bos_token": "<|endoftext|>",
|
| 3 |
+
"eos_token": "<|endoftext|>",
|
| 4 |
+
"unk_token": "<|endoftext|>"
|
| 5 |
+
}
|
stage1/tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
stage1/tokenizer_config.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_prefix_space": false,
|
| 3 |
+
"added_tokens_decoder": {
|
| 4 |
+
"50256": {
|
| 5 |
+
"content": "<|endoftext|>",
|
| 6 |
+
"lstrip": false,
|
| 7 |
+
"normalized": true,
|
| 8 |
+
"rstrip": false,
|
| 9 |
+
"single_word": false,
|
| 10 |
+
"special": true
|
| 11 |
+
}
|
| 12 |
+
},
|
| 13 |
+
"bos_token": "<|endoftext|>",
|
| 14 |
+
"clean_up_tokenization_spaces": false,
|
| 15 |
+
"eos_token": "<|endoftext|>",
|
| 16 |
+
"extra_special_tokens": {},
|
| 17 |
+
"model_max_length": 1024,
|
| 18 |
+
"tokenizer_class": "GPT2Tokenizer",
|
| 19 |
+
"unk_token": "<|endoftext|>"
|
| 20 |
+
}
|
stage1/vocab.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
stage2/config.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_num_labels": 1,
|
| 3 |
+
"activation_function": "gelu_new",
|
| 4 |
+
"architectures": [
|
| 5 |
+
"GPT2LMHeadModel"
|
| 6 |
+
],
|
| 7 |
+
"attn_pdrop": 0.1,
|
| 8 |
+
"bos_token_id": 50256,
|
| 9 |
+
"embd_pdrop": 0.1,
|
| 10 |
+
"eos_token_id": 50256,
|
| 11 |
+
"id2label": {
|
| 12 |
+
"0": "LABEL_0"
|
| 13 |
+
},
|
| 14 |
+
"initializer_range": 0.02,
|
| 15 |
+
"label2id": {
|
| 16 |
+
"LABEL_0": 0
|
| 17 |
+
},
|
| 18 |
+
"layer_norm_epsilon": 1e-05,
|
| 19 |
+
"model_type": "gpt2",
|
| 20 |
+
"n_ctx": 1024,
|
| 21 |
+
"n_embd": 768,
|
| 22 |
+
"n_head": 12,
|
| 23 |
+
"n_inner": null,
|
| 24 |
+
"n_layer": 6,
|
| 25 |
+
"n_positions": 1024,
|
| 26 |
+
"reorder_and_upcast_attn": false,
|
| 27 |
+
"resid_pdrop": 0.1,
|
| 28 |
+
"scale_attn_by_inverse_layer_idx": false,
|
| 29 |
+
"scale_attn_weights": true,
|
| 30 |
+
"summary_activation": null,
|
| 31 |
+
"summary_first_dropout": 0.1,
|
| 32 |
+
"summary_proj_to_labels": true,
|
| 33 |
+
"summary_type": "cls_index",
|
| 34 |
+
"summary_use_proj": true,
|
| 35 |
+
"task_specific_params": {
|
| 36 |
+
"text-generation": {
|
| 37 |
+
"do_sample": true,
|
| 38 |
+
"max_length": 50
|
| 39 |
+
}
|
| 40 |
+
},
|
| 41 |
+
"torch_dtype": "float32",
|
| 42 |
+
"transformers_version": "4.52.2",
|
| 43 |
+
"use_cache": true,
|
| 44 |
+
"vocab_size": 50257
|
| 45 |
+
}
|
stage2/generation_config.json
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_from_model_config": true,
|
| 3 |
+
"bos_token_id": 50256,
|
| 4 |
+
"eos_token_id": 50256,
|
| 5 |
+
"transformers_version": "4.52.2"
|
| 6 |
+
}
|
stage2/merges.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
stage2/model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:721fa38acb2ba5d1ebdeed4bad3dcb32c0beeb2b924ecf544fffaa3b0bb65a66
|
| 3 |
+
size 327657928
|
stage2/special_tokens_map.json
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"bos_token": "<|endoftext|>",
|
| 3 |
+
"eos_token": "<|endoftext|>",
|
| 4 |
+
"unk_token": "<|endoftext|>"
|
| 5 |
+
}
|
stage2/tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
stage2/tokenizer_config.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_prefix_space": false,
|
| 3 |
+
"added_tokens_decoder": {
|
| 4 |
+
"50256": {
|
| 5 |
+
"content": "<|endoftext|>",
|
| 6 |
+
"lstrip": false,
|
| 7 |
+
"normalized": true,
|
| 8 |
+
"rstrip": false,
|
| 9 |
+
"single_word": false,
|
| 10 |
+
"special": true
|
| 11 |
+
}
|
| 12 |
+
},
|
| 13 |
+
"bos_token": "<|endoftext|>",
|
| 14 |
+
"clean_up_tokenization_spaces": false,
|
| 15 |
+
"eos_token": "<|endoftext|>",
|
| 16 |
+
"extra_special_tokens": {},
|
| 17 |
+
"model_max_length": 1024,
|
| 18 |
+
"tokenizer_class": "GPT2Tokenizer",
|
| 19 |
+
"unk_token": "<|endoftext|>"
|
| 20 |
+
}
|
stage2/vocab.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
tiny_chained_tossup.py
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Chained pipeline:
|
| 3 |
+
• Stage-A: classify hypothesis vs. premise → label distribution (Y)
|
| 4 |
+
• Stage-B: consume Y (+ original text) → final dict {guess, confidence, explanation}
|
| 5 |
+
The outer task id is "qpe-tossup" (or "qpe-bonus", pick one).
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
# %%s
|
| 9 |
+
import os
|
| 10 |
+
|
| 11 |
+
from dotenv import load_dotenv
|
| 12 |
+
|
| 13 |
+
load_dotenv(os.path.expanduser("~/.zshenv"))
|
| 14 |
+
from pathlib import Path
|
| 15 |
+
|
| 16 |
+
import torch
|
| 17 |
+
import torch.nn.functional as F
|
| 18 |
+
from transformers import (
|
| 19 |
+
AutoModelForSequenceClassification,
|
| 20 |
+
AutoTokenizer,
|
| 21 |
+
Pipeline,
|
| 22 |
+
pipeline,
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
class QBChainedPipeline(Pipeline):
|
| 27 |
+
def __init__(self, pipeA, pipeB, **kwargs):
|
| 28 |
+
if pipeA.task != "text-generation" or pipeB.task != "text-generation":
|
| 29 |
+
raise ValueError(
|
| 30 |
+
f"Both stages must be text-generation pipelines, but got {pipeA.task} and {pipeB.task}"
|
| 31 |
+
)
|
| 32 |
+
self.pipeA = pipeA
|
| 33 |
+
self.pipeB = pipeB
|
| 34 |
+
super().__init__(
|
| 35 |
+
model=None, tokenizer=None, task="quizbowl-tossup", **kwargs
|
| 36 |
+
) # we call sub-pipelines manually
|
| 37 |
+
|
| 38 |
+
# ---- Standard Pipeline API overrides ----------------------------------
|
| 39 |
+
|
| 40 |
+
def _sanitize_parameters(self, **pipeline_kwargs):
|
| 41 |
+
"""
|
| 42 |
+
Forward every keyword argument to the inner generators unchanged.
|
| 43 |
+
"""
|
| 44 |
+
return pipeline_kwargs, {}, {}
|
| 45 |
+
|
| 46 |
+
def preprocess(self, inputs, **kwargs):
|
| 47 |
+
"""
|
| 48 |
+
No special preprocessing—just forward the raw input string.
|
| 49 |
+
"""
|
| 50 |
+
return inputs
|
| 51 |
+
|
| 52 |
+
def _forward(self, inputs, *args, **kw):
|
| 53 |
+
"""
|
| 54 |
+
inputs: {"question_text": str}
|
| 55 |
+
returns: {"answer": str, "confidence": float, "explanation": str}
|
| 56 |
+
"""
|
| 57 |
+
question_text = inputs["question_text"]
|
| 58 |
+
# -------- Stage A --------
|
| 59 |
+
promptA = f"Answer the quiz question revealed so far:\n Question:{question_text}\nAnswer:"
|
| 60 |
+
outA = self.pipeA(promptA)[0]["generated_text"]
|
| 61 |
+
answer = outA.removeprefix(promptA).strip()
|
| 62 |
+
|
| 63 |
+
# -------- Stage B --------
|
| 64 |
+
promptB = f"Given the question and the answer, output the confidence score between 0 and 1:\n Question:{question_text}\nAnswer: {answer}\nConfidence:"
|
| 65 |
+
outB = self.pipeB(promptB)[0]["generated_text"]
|
| 66 |
+
confidence = float(outB.removeprefix(promptB).strip())
|
| 67 |
+
|
| 68 |
+
return {"answer": answer, "confidence": confidence}
|
| 69 |
+
|
| 70 |
+
def postprocess(self, model_outputs):
|
| 71 |
+
"""
|
| 72 |
+
Hugging Face pipelines expect structured output.
|
| 73 |
+
"""
|
| 74 |
+
return {
|
| 75 |
+
**model_outputs,
|
| 76 |
+
"explanation": f"Confidence score for the answer '{model_outputs['answer']}' is {model_outputs['confidence']}.",
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
# %%
|