Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tiktoken tokenizers are not pickable #5769

Closed
markovalexander opened this issue Apr 18, 2023 · 1 comment
Closed

Tiktoken tokenizers are not pickable #5769

markovalexander opened this issue Apr 18, 2023 · 1 comment

Comments

@markovalexander
Copy link

Describe the bug

Since tiktoken tokenizer is not pickable, it is not possible to use it inside dataset.map() with multiprocessing enabled. However, you made tiktoken's tokenizers pickable in datasets==2.10.0 for caching. For some reason, this logic does not work in dataset processing and raises TypeError: cannot pickle 'builtins.CoreBPE' object

Steps to reproduce the bug

from datasets import load_dataset
import tiktoken

dataset = load_dataset("stas/openwebtext-10k")

enc = tiktoken.get_encoding("gpt2")

tokenized = dataset.map(
    process,
    remove_columns=['text'],
    desc="tokenizing the OWT splits",
    num_proc=2,
)

def process(example):
        ids = enc.encode(example['text'])
        ids.append(enc.eot_token)
        out = {'ids': ids, 'len': len(ids)}
        return out

Expected behavior

starts processing dataset

Environment info

  • datasets version: 2.11.0
  • Platform: Linux-5.15.0-1021-oracle-x86_64-with-glibc2.29
  • Python version: 3.8.10
  • Huggingface_hub version: 0.13.4
  • PyArrow version: 9.0.0
  • Pandas version: 2.0.0
@albertvillanova
Copy link
Member

Thanks for reporting, @markovalexander.

Unfortunately, I'm not able to reproduce the issue: the tiktoken tokenizer can be used within Dataset.map, both in my local machine and in a Colab notebook: https://colab.research.google.com/drive/1DhJroZgk0sNFJ2Mrz-jYgrmh9jblXaCG?usp=sharing

Are you sure you are using datasets version 2.11.0?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants