Downloads · 30 days
13
21% of all-time downloads
RichardErkhov/robowaifudev_-_megatron-gpt2-345m-4bits
robowaifudev_-_megatron-gpt2-345m-4bits is a text generation model from RichardErkhov. Use it when you need the model to write or continue text. It is set up for transformers.
Downloads · 30 days
13
21% of all-time downloads
All-time downloads
61
Public
Parameters
360M
276 MB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors276 MB · 99%
How the weights are stored.
U8302M · 84%
From the Hugging Face model README
Quantization made by Richard Erkhov.
megatron-gpt2-345m - bnb 4bits
language:
This is an archive of nvidia/megatron-gpt2-345m that contains readily available model weights (375M). Its performance on Wikitext-103 is 19.31.<sup>1</sup> In comparison, the performance of GPT2-large (1.5B) is 17.48 and GPT2-medium (762M) is 22.05.<sup>2</sup>
Megatron is a large, powerful transformer developed by the Applied Deep Learning Research team at NVIDIA. This particular Megatron model was trained from a generative, left-to-right transformer in the style of GPT-2. This model was trained on text sourced from Wikipedia, RealNews, OpenWebText, and CC-Stories. It contains 345 million parameters.
Find more information at https://github.com/NVIDIA/Megatron-LM
The following code shows how to use the Megatron GPT2 checkpoint and Transformers to generate text.
import os
import torch
from transformers import GPT2Tokenizer, GPT2LMHeadModel
tokenizer = GPT2Tokenizer.from_pretrained("gpt2")
model = GPT2LMHeadModel.from_pretrained("robowaifudev/megatron-gpt2-345m")
if torch.cuda.is_available():
device = torch.device("cuda")
model.half()
else:
device = torch.device("cpu")
model.to(device)
model.eval()
# Generate
prompt = (
"It was a bright cold day in April, and the clocks were striking thirteen. Winston Smith,"
)
input_ids = tokenizer.encode(prompt, return_tensors="pt").to(device)
output = model.generate(
input_ids=input_ids,
max_length=len(input_ids) + 128,
do_sample=True,
top_k=64,
top_p=0.9,
temperature=0.8,
num_return_sequences=2,
repetition_penalty=1.025
)
# Output the text
print("Prompt:", prompt)
print("*" * 3)
for i, sentence in enumerate(output):
text = tokenizer.decode(sentence, clean_up_tokenization_spaces=True)
print(f"{i}:", text)
print("*" * 3)
The original Megatron code can be found here: https://github.com/NVIDIA/Megatron-LM.