unsloth icon indicating copy to clipboard operation
unsloth copied to clipboard

Issue with phi-3 on Long Sequences with Batches > 1

Open Samoed opened this issue 1 year ago • 6 comments

Hi! I'm encountering an issue while tuning phi-3 on long sequences with batch sizes greater than 1. Below is the code to reproduce the problem:

Working Code:

tokenized = tokenizer(
    ["Very long prompt\n" * 3000],  # *2,
    max_length=3000,
    return_tensors="pt",
    truncation=True,
).to("cuda")

res = model.generate(
    **tokenized,
    max_length=4096,
)

Code with Error:

RuntimeError: The expanded size of the tensor (2047) must match the existing size (3001) at non-singleton dimension 3. Target sizes: [2, 32, 1, 2047]. Tensor sizes: [2, 1, 1, 3001]
tokenized = tokenizer(
    ["Very long prompt\n" * 3000] * 2,
    max_length=3000,
    return_tensors="pt",
    truncation=True,
).to("cuda")

res = model.generate(
    **tokenized,
    max_length=4096,
)

Notebook with example.

Any insights on how to resolve this issue would be greatly appreciated!

Samoed avatar May 16 '24 19:05 Samoed

Oh interesting I'll check this and get back to you - sorry!

danielhanchen avatar May 17 '24 18:05 danielhanchen

The problem still exists. It seems there is a 2048 token limit for the Phi-3 mini/medium model, but not for other models in Unsloth

xinxin-chen avatar Jul 17 '24 20:07 xinxin-chen

Apologies I'll escalate this to higher priority - will try getting a fix for this

danielhanchen avatar Jul 18 '24 07:07 danielhanchen