Views
No views yet
1import torch
2from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig, GemmaTokenizer
3
4model_id = "alibidaran/Gemma2_Python_instruction"
5bnb_config = BitsAndBytesConfig(
6 load_in_4bit=True,
7 bnb_4bit_quant_type="nf4",
8 bnb_4bit_compute_dtype=torch.bfloat16
9)
10
11
12tokenizer = AutoTokenizer.from_pretrained(model_id)
13model = AutoModelForCausalLM.from_pretrained(model_id, quantization_config=bnb_config, device_map={"":0})
14prompt = """
15Connect to a MongoDB database, select all documents from the collection ‘customers’ where the 'age' field is greater than 30 and the 'gender' field is 'female'. Then, for each selected document, retrieve the corresponding document from another collection called 'orders' based on the 'customer_id' field. Finally, display the documents in ascending order based on the 'last_name' field. The expected time complexity for retrieving the documents from the 'customers' collection should be O(n), where n is the total number of documents in the collection. The expected time complexity for retrieving the corresponding documents from the 'orders' collection for each selected document should also be O(n), where n is the total number of selected documents.
16"""
17text=f"<s> ##Instruction: {prompt}: ##Output "
18inputs=tokenizer(text,return_tensors='pt').to('cuda')
19outputs=model.generate(**inputs,max_new_tokens=400,do_sample=True,top_p=0.92,top_k=10,temperature=0.7)
20print(tokenizer.decode(outputs[0], skip_special_tokens=True))
21