Views
No views yet

1
2model_id = "jpacifico/French-Alpaca-Llama3-8B-Instruct-v1.0"
3model = AutoModelForCausalLM.from_pretrained(model_id, quantization_config=bnb_config, device_map={"":0})
4tokenizer = AutoTokenizer.from_pretrained(model_id, add_eos_token=True, padding_side='left')
5streamer = TextStreamer(tokenizer, timeout=10.0, skip_prompt=True, skip_special_tokens=True)
6
7def stream_frenchalpaca(user_prompt):
8 runtimeFlag = "cuda:0"
9 system_prompt = 'Tu trouveras ci-dessous une instruction qui décrit une tâche. Rédige une réponse qui complète de manière appropriée la demande.\n\n'
10 B_INST, E_INST = "### Instruction:\n", "### Response:\n"
11 prompt = f"{system_prompt}{B_INST}{user_prompt.strip()}\n\n{E_INST}"
12 inputs = tokenizer([prompt], return_tensors="pt").to(runtimeFlag)
13 streamer = TextStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
14 _ = model.generate(**inputs, streamer=streamer, max_new_tokens=500)
15
16stream_frenchalpaca("your prompt here")