File size: 1,372 Bytes
d990a0f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | import os
import numpy as np
import random
from transformers import GPT2Tokenizer
# --- Settings ---
BIN_PATH = "data_19b.bin"
NUM_SAMPLES = 10
SAMPLE_LEN = 200 # Number of tokens to decode per sample
def main():
if not os.path.exists(BIN_PATH):
print(f"Error: {BIN_PATH} not found.")
return
# 1. Load the tokenizer
print("Loading GPT-2 Tokenizer...")
tokenizer = GPT2Tokenizer.from_pretrained("EleutherAI/gpt-neox-20b")
# 2. Map the data (instantly points to the 40GB file)
data = np.memmap(BIN_PATH, dtype=np.uint16, mode='r')
total_tokens = len(data)
print(f"File loaded. Total tokens: {total_tokens:,}")
# 3. Pick random spots and decode
print(f"\n--- Decoding {NUM_SAMPLES} Random Samples ---\n")
for i in range(NUM_SAMPLES):
# Pick a random starting index
start_idx = random.randint(0, total_tokens - SAMPLE_LEN)
end_idx = start_idx + SAMPLE_LEN
# Pull the uint16 tokens and convert to standard Python list
token_ids = data[start_idx:end_idx].tolist()
# Decode to text
decoded_text = tokenizer.decode(token_ids, skip_special_tokens=True)
print(f"Sample {i+1} (Index {start_idx:,}):")
print("-" * 50)
print(decoded_text)
print("-" * 50 + "\n")
if __name__ == "__main__":
main() |