Views
No views yet
kaifkhaan/roast).kaifkhaan/roast dataset will be reflected in the model's outputs. This could include biases related to various demographics, stereotypes, or sensitive topics present in the original data. Rigorous testing and filtering are required for any application.transformers library. Ensure you have transformers, torch, peft, bitsandbytes (if using 4-bit loading), and trl installed.pip install transformers torch peft bitsandbytes trlpipeline:1from transformers import pipeline
2import torch
3
4# Specify the repository ID
5model_repo_id = "AnnasShaikh/TinyLlama-1.1B-Chat-Roast" # Make sure this matches your actual repo ID
6
7# Load the pipeline (adjust device if needed, e.g., device="cpu")
8# You might need to load the model with quantization config if it was saved that way
9# or use AutoModelForCausalLM.from_pretrained directly with PEFT
10try:
11 generator = pipeline(
12 "text-generation",
13 model=model_repo_id,
14 # You might need to specify quantization config here if the model was saved with it
15 # device="cuda" if torch.cuda.is_available() else "cpu",
16 torch_dtype=torch.float16 # Recommended for inference if supported by hardware
17 )
18 print(f"Pipeline loaded for model {model_repo_id}")
19
20 # Example chat interaction
21 prompt = "Hello, tell me something about yourself." # Try a generic prompt first
22 prompt_roast = "You can't roast me!" # Try a roasting-specific prompt
23
24 # Format the prompt in the chat format used during training
25 # This format must match the one in your format_chat_prompt function
26 chat_prompt_formatted = f"<|user|>\n{prompt_roast}\n<|assistant|>\n"
27
28 print(f"\nInput formatted prompt:\n{chat_prompt_formatted}")
29
30 # Generate output
31 # Adjust generation parameters for desired creativity/determinism
32 output = generator(
33 chat_prompt_formatted,
34 max_new_tokens=100,
35 num_beams=1, # Use 1 for greedy or sampling
36 do_sample=True, # Set to True for sampling
37 temperature=0.7,
38 top_k=50,
39 top_p=0.95,
40 # stop_sequence=['<|user|>'] # Optional: Stop generation before the next user turn
41 )
42
43 generated_text = output[0]
44
45 print("\n--- Generated Text ---")
46 # The output includes the input prompt, you might want to trim it
47 print(generated_text)
48 print("----------------------")
49
50except Exception as e:
51 print(f"Error loading model or generating text: {e}")
52 print("Please ensure you have the necessary libraries installed (transformers, torch, peft, bitsandbytes, trl)")
53 print("And that the model repository ID is correct and the model is accessible.")
54pipeline might need adjustments to correctly load the PEFT adapter and base model, especially with quantization. For more reliable loading of PEFT models with quantization, you might need to load the model using AutoPeftModelForCausalLM.from_pretrained and the tokenizer separately, as shown in your original inference code block, and then use the model's generate method directly instead of the pipeline.1@misc{vonwerra2022trl,
2 title = {{TRL: Transformer Reinforcement Learning}},
3 author = {Leandro von Werra and Younes Belkada and Lewis Tunstall and Edward Beeching and Tristan Thrush and Nathan Lambert and Shengyi Huang and Kashif Rasul and Quentin Gallou{\'e}dec},
4 year = 2020,
5 journal = {GitHub repository},
6 publisher = {GitHub},
7 howpublished = {\url{https://github.com/huggingface/trl}}