Views
No views yet
1# !pip install "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
2# !pip install --no-deps xformers "trl<0.9.0" peft accelerate bitsandbytes
3from unsloth import FastLanguageModel
4model, tokenizer = FastLanguageModel.from_pretrained(
5 model_name = "date3k2/llama3-8b-instruct-sharegpt",
6 max_seq_length = 2048,
7 dtype = None,
8 load_in_4bit = True,
9)
10FastLanguageModel.for_inference(model) # Enable native 2x faster inference
11
12messages = [
13 {"from": "human", "value": "Hãy gợi ý một số địa điểm du lịch ở Hà Nội."},
14]
15inputs = tokenizer.apply_chat_template(
16 messages,
17 tokenize = True,
18 add_generation_prompt = True, # Must add for generation
19 return_tensors = "pt",
20).to("cuda")
21
22from transformers import TextStreamer
23text_streamer = TextStreamer(tokenizer)
24_ = model.generate(input_ids = inputs, streamer = text_streamer, max_new_tokens = 512, use_cache = True)
25