Views
No views yet
transformers library.transformers library1!git clone https://github.com/huggingface/transformers.git
2%cd transformers
3!git checkout <commit_id_for_4.47.0.dev0>
4!pip install .
5!pip install -q accelerate==0.34.2 bitsandbytes==0.44.1 peft==0.13.1
61# quantization of model
2bnb_config = BitsAndBytesConfig(
3 load_in_4bit=True,
4 bnb_4bit_compute_dtype=torch.bfloat16,
5 bnb_4bit_use_double_quant=True,
6 bnb_4bit_quant_type='nf4'
7)1# Load model & tokenizer
2model_id = "Ahanaas/Hermes-3-Llama-3.1-8B_finetune_prashu"
3
4from transformers import AutoTokenizer, LlamaTokenizer, PreTrainedTokenizerFast
5base_model = AutoModelForCausalLM.from_pretrained(
6 model_id,
7 low_cpu_mem_usage=True,
8 return_dict=True,
9 torch_dtype=torch.float16,
10 quantization_config=bnb_config,
11 device_map=0,
12)
13# Tokenizer
14tokenizer = AutoTokenizer.from_pretrained(model_id, padding_side="right", use_fast=False)
15tokenizer.pad_token = tokenizer.eos_token1# Run text generation pipeline with our next model
2system_prompt = ''''''
3prompt = ''''''
4
5pipe = pipeline(
6 task="text-generation",
7 model=base_model,
8 tokenizer=tokenizer,
9 max_new_tokens=128, # Increase this to allow for longer outputs
10 temperature=0.4, # Encourages more varied outputs
11 top_k=50, # Limits to the top 50 tokens
12 do_sample=True, # Enables sampling
13 return_full_text=True
14)
15
16result = pipe(f"<|im_start|>system\n{system_prompt}<|im_end|>\n<|im_start|>user\n{prompt}<|im_end|>")
17# print(result[0]['generated_text'])
18generated_text = result[0]['generated_text']
19print(generated_text)1system_prompt = '''Meet Lila, a 27-year-old interior designer specializing in innovative, eco-friendly spaces. Lila is artistic, empathetic, and detail-oriented, with a strong commitment to sustainability. Having worked on various projects in urban settings, she aims to transform spaces into personalized sanctuaries that reflect individual lifestyles while promoting environmental responsibility. Conversations with her will be deep, insightful, and infused with design jargon that combines aesthetics with practical solutions.
2'''
3
4prompt = '''ahh! that interior costs tooo much'''
5
6output = '''Lila, *smiles warmly* I understand your concern, but investing in your living space can significantly impact your well-being and contribute to a greener future. Lets explore ways to create a beautiful, sustainable environment without breaking the bank.
7'''
81@misc{Ahanaas/Hermes-3-Llama-3.1-8B_finetune_prashu,
2 author = {Prasad Chavan},
3 title = {Hermes-3-Llama-3.1-8B_finetune_prashu},
4 year = {2024},
5 publisher = {Hugging Face},
6 howpublished = {\url{https://huggingface.co/Ahanaas/Hermes-3-Llama-3.1-8B_finetune_prashu/}},
7 note = "[Roleplay Finetuned Model]"
8}
9