Views
No views yet
Pretrained model on English language using a causal language modeling (CLM) objective. It was introduced in this paper and first released at this page.
GPT-2 is a transformers model pretrained on a very large corpus of English data in a self-supervised fashion. This means it was pretrained on the raw texts only, with no humans labelling them in any way (which is why it can use lots of publicly available data) with an automatic process to generate inputs and labels from those texts. More precisely, it was trained to guess the next word in sentences. More precisely, inputs are sequences of continuous text of a certain length and the targets are the same sequence, shifted one token (word or piece of word) to the right. The model uses internally a mask-mechanism to make sure the predictions for the tokenionly uses the inputs from1toibut not the future tokens. This way, the model learns an inner representation of the English language that can then be used to extract features useful for downstream tasks. The model is best at what it was pretrained for however, which is generating texts from a prompt.
{
"n_embd": 1600,
"n_head": 25,
"n_layer": 48,
"n_positions": 1024,
}%pip install -qq transformers accelerate bitsandbytes1from transformers import AutoModelForCausalLM, AutoTokenizer
2from transformers import BitsAndBytesConfig
3import torch
4
5model_id = "crumbly/gpt2-linear-xl-sharded-bf16"
6bnb_config = BitsAndBytesConfig(
7 load_in_4bit=True,
8 bnb_4bit_use_double_quant=True,
9 bnb_4bit_quant_type="nf4",
10 bnb_4bit_compute_dtype=torch.bfloat16
11)
12
13tokenizer = AutoTokenizer.from_pretrained(model_id)
14model = AutoModelForCausalLM.from_pretrained(
15 model_id,
16 trust_remote_code=True,
17 device_map={"":0},
18 quantization_config=bnb_config
19)1inputs = tokenizer("Once upon a time,", return_tensors='pt')
2inputs = {
3 k:v.cuda() for k,v in inputs.items()
4}
5outputs = model.generate(
6 **inputs,
7 max_new_tokens=32,
8 temperature=0.7,
9 do_sample=True
10)
11tokenizer.decode(outputs[0])