Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions open_lm/datapreprocess/make_2048.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import argparse
from pathlib import Path
from transformers import GPTNeoXTokenizerFast

import smart_open

# ========================================
# = Global variables =
Expand Down Expand Up @@ -52,10 +52,17 @@ def upload_to_s3_and_remove(fname):

@contextmanager
def get_item_reader(file_name):
"""Creates iterator for reading .jsonl files or Zstd compressed .jsonl files"""
"""
Creates iterator for reading .jsonl files, gzip compressed,
or Zstd compressed .jsonl files
"""
if file_name.endswith(".jsonl"):
with jsonlines.open(file_name) as reader:
yield reader
elif file_name.endswith((".jsonl.gz", ".json.gz")):
with smart_open.open(file_name, "r") as f:
with jsonlines.Reader(f) as reader:
yield reader
else:
dctx = zstd.ZstdDecompressor()
with open(file_name, "rb") as compressed_file:
Expand Down