Skip to content

to_sharegpt seems did not works properly in some cases #1769

Closed

Description

@SSARCandy

See below example, load_dataset works normally but after to_sharegpt, the dataset become empty.

from pprint import pprint
from datasets import load_dataset

# fizzbuzz123.csv
'''
Query,Answer
"123?","456"
"1234?","456"
"12345?","456"
"123456?","456"
"1234567?","456"
'''
dataset = load_dataset(
    "csv",
    data_files = "./fizzbuzz123.csv",
    split = "train",
)
print(dataset.column_names, len(dataset))
print(dataset[0])
print(dataset[-1])

from unsloth import to_sharegpt
dataset = to_sharegpt(
    dataset,
    # merged_prompt = "{Query}",
    merged_column_name = "Query",
    output_column_name = "Answer",
)
pprint(dataset)


from unsloth import standardize_sharegpt
dataset = standardize_sharegpt(dataset)

output

['Query', 'Answer'] 5
{'Query': '123?', 'Answer': 456}
{'Query': '1234567?', 'Answer': 456}
🦥 Unsloth: Will patch your computer to enable 2x faster free finetuning.
🦥 Unsloth Zoo will now patch everything to make training faster!
Dataset({
    features: [],
    num_rows: 0
})
Traceback (most recent call last):
  File "/home/avenger2/git/test/bug2.py", line 24, in <module>
    dataset = standardize_sharegpt(dataset)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/avenger2/.pyenv/versions/3.11.11/lib/python3.11/site-packages/unsloth/chat_templates.py", line 1418, in standardize_sharegpt
    convos = dataset[:10]["conversations"]
             ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
KeyError: 'conversations'

and below is my environment

🦥 Unsloth: Will patch your computer to enable 2x faster free finetuning.
🦥 Unsloth Zoo will now patch everything to make training faster!
==((====))==  Unsloth 2025.2.12: Fast Llama patching. Transformers: 4.48.3.
   \\   /|    GPU: NVIDIA A100-PCIE-40GB. Max memory: 39.431 GB. Platform: Linux.
O^O/ \_/ \    Torch: 2.6.0+cu124. CUDA: 8.0. CUDA Toolkit: 12.4. Triton: 3.2.0
\        /    Bfloat16 = TRUE. FA [Xformers = 0.0.29.post3. FA2 = False]
 "-____-"     Free Apache license: http://github.com/unslothai/unsloth
Unsloth: Fast downloading is enabled - ignore downloading bars which are red colored!

Activity

  1. danielhanchen commented on Feb 23, 2025

    @danielhanchen
    Member

    Oh that's not good :(
    @Erland366 It'll be cool if you could make a patch - appreciate it :)

  2. rolandtannous commented on Jun 30, 2025

    @rolandtannous
    Contributor

    Hello ,

    This should now be solved in the latest version of Unsloth.
    Please make sure to upgrade your installation to the latest version using

    pip install --upgrade unsloth-zoo
    pip install --upgrade unsloth
    

    Will close this for now.
    Please feel free to comment back if you are still facing the same issue after trying the above.
    Thank you for using Unsloth

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    currently fixing

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions