Repository navigation
Closed
Labels
fixed - pending confirmationFixed, waiting for confirmation from poster
Description
Using the Kaggle 2X T4 GPU environment, 7B models have a considerable reduction in speed compared to without unsloth.
from unsloth import FastLanguageModel
import torch
max_seq_length = 2048 # Choose any! We auto support RoPE Scaling internally!
dtype = None # None for auto detection. Float16 for Tesla T4, V100, Bfloat16 for Ampere+
load_in_4bit = True # Use 4bit quantization to reduce memory usage. Can be False.
# use mistral 7B for this section
model, tokenizer = FastLanguageModel.from_pretrained(
model_name = "unsloth/mistral-7b-bnb-4bit",
max_seq_length = max_seq_length,
dtype = dtype,
load_in_4bit = load_in_4bit,
device_map = "auto"
# token = "hf_...", # use one if using gated models like meta-llama/Llama-2-7b-hf
)
alpaca_prompt = """Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
### Instruction:
{}
### Input:
{}
### Response:
{}"""
import time
FastLanguageModel.for_inference(model) # Enable native 2x faster inference
time_initial = time.time()
inputs = tokenizer(
[
alpaca_prompt.format(
"Generate a way to transform text in accordance with the input.", # instruction
"Make 100 creative ways to transform text, and number them. For example: \"Convert this into a sea shanty\" or \"Rewrite this text as a presidential speech\". Do not generate fewer than 100 texts. Only mention transformations related to the text.", # input
"", # output - leave this blank for generation!
)
], return_tensors = "pt").to("cuda")
outputs = model.generate(**inputs, max_new_tokens=2048, use_cache=True, do_sample=True)
output = tokenizer.batch_decode(outputs)
print(output)
time_final = time.time()
print(f'{round(time_final - time_initial, 2)}s - {round(150 / (time_final - time_initial), 2)}tok/s')Output:
...generated text...
58.29s - 2.57tok/s
Any ideas of what I'm doing wrong?
Metadata
Metadata
Assignees
Labels
fixed - pending confirmationFixed, waiting for confirmation from poster
Activity
danielhanchen commentedon Mar 18, 2024
@JIBSIL What's the generation speed without Unsloth in Kaggle? Also why 150/? Shouldn't it be len(output)/?
JIBSIL commentedon Mar 19, 2024
Ah yes, thank you for that; I originally was only generating 150 tokens. However, running the same code now yields this output:
Not sure what the issue could be. When I remove this line:
FastLanguageModel.for_inference(model) # Enable native 2x faster inferenceit crashes the kernel.
danielhanchen commentedon Mar 19, 2024
@JIBSIL Whoops my bad - I think I fixed it now!
JIBSIL commentedon Mar 25, 2024
Great - Seems to be working! But now, the model is spamming the
<bos>token when asked to make a longer generation-Here's a pastebin of the log as Github won't let me post
<bos>into a code block https://pastes.io/pawpw2voogHowever Mistral works perfectly with the same prompt.
HirCoir commentedon Mar 27, 2024
I also have the same problem with almost all the models... I have put aside the interest in Unsloth until the community finds the issue and it's fixed.
danielhanchen commentedon Mar 27, 2024
@HirCoir Apologies sorry was extremely busy this week so didn't have time to look at this! I'll see what I can do! @JIBSIL Also sorry did not respond until now! This is after a finetune right? Did you manage to add EOS during finetuning?
Also @HirCoir you said this happens with non Gemma as well? Did you add EOS to the end of each prompt after finetuning? Are you calling a base model or instruct versions (with or no finetuning?)
JIBSIL commentedon Apr 2, 2024
@danielhanchen - The issue seems to have fixed itself - looks like it was a case of persisting variables meddling with something in my notebook.
This may be a bit out of scope for the issue, but perhaps you would be able to help. I am testing batch generation using a set of variable length texts, which can have a speedup of over 10x under the correct circumstances. However, it seems to just be generating gibberish. I've tested a few strategies outlined here and in this pr but it appears that the only real resources that exist for this are for GPT-2.
I am initializing like this:
and generating using this code:
which yields this output
danielhanchen commentedon Apr 3, 2024
@JIBSIL Fixed batched inference yesterday (after your comment!!) See #267 (comment) for more info. You'll need to update Unsloth without any dependency updates via
pip install --upgrade --force-reinstall --no-cache-dir git+https://github.com/unslothai/unsloth.gitfor local installations (no need for Colab / Kaggle)JIBSIL commentedon Apr 6, 2024
Looks like it works! However- when trying to repeatedly generate batches, a CUDA out of memory error eventually occurs:
The offending code:
It's quite strange, because the code worked a few versions ago (albeit on the 2b version; perhaps the use of the 7b version is causing the error). Could there be a GPU memory leak?
danielhanchen commentedon Apr 7, 2024
@JIBSIL Hmmm could be im not freeing something - let me check
danielhanchen commentedon Apr 18, 2024
@JIBSIL Much apologies on the delay - its possible there are small memory fragmentations over time, which will cause OOMs, but ye its possibly cause ur doing 7B and not 2B now, and so it gets more pronounced - I don't see a memory leak in my tests for now ie below uses like 20GB of VRAM on a L4:
Then I used
nvidia-smito check for VRAM usage, and it doesn't look like there are any leaks (for now)It could be intermittent, though unsure
JIBSIL commentedon Apr 22, 2024
It was actually a problem on my end-- some of the texts in my test set were drastically longer than others. My bad.
Merge pull request unslothai#260 from unslothai/fix/fix-vision-proces…
CI(notebooks): cross-repo validator for unslothai/notebooks