gokaygokay's picture
Update README.md
9af8e61 verified
metadata
library_name: transformers
tags:
  - art
datasets:
  - gokaygokay/prompt_description_stable_diffusion_3k
language:
  - en
pipeline_tag: text2text-generation
pip install -q -U transformers trl accelerate peft bitsandbytes
from transformers import AutoModelForCausalLM, GenerationConfig, AutoTokenizer
import torch
import os

model_id = "gokaygokay/tiny_llama_chat_description_to_prompt"
model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.float16, load_in_8bit=False,
                                             device_map="auto",
                                             trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained(model_id)
tokenizer.pad_token = tokenizer.eos_token

def generate_response(user_input):

  prompt = f"<|im_start|>user\n{user_input}<|im_end|>\n<|im_start|>assistant:"

  inputs = tokenizer([prompt], return_tensors="pt")
  generation_config = GenerationConfig(penalty_alpha=0.6,do_sample = True,
      top_k=5,temperature=0.9,repetition_penalty=1.2,
      max_new_tokens=100,pad_token_id=tokenizer.eos_token_id
  )

  inputs = tokenizer(prompt, return_tensors="pt").to('cuda')

  outputs = model.generate(**inputs, generation_config=generation_config)
  print(tokenizer.decode(outputs[0], skip_special_tokens=True))