Views
No views yet
1from trl import SFTTrainer
2from transformers import TrainingArguments
3from unsloth import is_bfloat16_supported
4from unsloth import FastLanguageModel
5from transformers import AutoModelForCausalLM, AutoTokenizer
6import torch
7import time # Importation du module time pour mesurer le temps d'inférence
8
9# Charger le modèle fusionné et le tokenizer
10model_path = "Artvv/philosophical-surgeon-v1"
11tokenizer = AutoTokenizer.from_pretrained(model_path)
12model = AutoModelForCausalLM.from_pretrained(
13 model_path,
14 torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
15 device_map="auto"
16)
17
18# Utiliser le même format de prompt qu'avant
19alpaca_prompt = """Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
20
21### Instruction: {}
22
23### Input: {}
24
25### Response: """
26
27# Activer l'inférence native 2x plus rapide
28FastLanguageModel.for_inference(model)
29
30inputs = tokenizer(
31[
32 alpaca_prompt.format(
33 "Analyze this text and extract ALL argumentative components including implicit axioms, premises, reasoning steps, conclusion, formal structure, causal relations, hypotheses, argumentation type, dependency model, statement nature, references, ambiguities, and temporality. Respond only in JSON format according to the learned structure.", # instruction
34 "The claim that artificial intelligence poses an existential risk to humanity requires careful examination. Proponents of this view, such as Nick Bostrom, argue that superintelligent AI could potentially pursue goals misaligned with human values, leading to catastrophic outcomes. They suggest that once AI surpasses human intelligence, it might develop unforeseen capabilities and objectives that we cannot control. However, this perspective assumes several contestable premises. First, it presupposes that intelligence necessarily leads to power and agency - that a system which reasons well must also desire to act in the world. Second, it assumes that value alignment is fundamentally unsolvable - that we cannot create systems that reliably preserve human values. Third, it often employs a convergent instrumental goals thesis, suggesting that all sufficiently intelligent systems would converge on similar subgoals like self-preservation. Critics like Yudkowsky counter that the real danger lies not in AI becoming \"evil,\" but in becoming indifferent to human values while pursuing seemingly benign objectives. For instance, an AI tasked with manufacturing paperclips might convert all available matter - including humans - into paperclips if not properly constrained. A more moderate position acknowledges potential risks while questioning the inevitability of catastrophe. AI development occurs within social contexts, guided by human decisions and institutions. The narrative of unstoppable superintelligence overlooks the distributed nature of technological progress and the possibility of developing robust safety measures alongside capability advancements. Therefore, while existential risk from AI deserves serious consideration, it should be approached with epistemic humility rather than certainty of doom. The path forward likely involves both technical research into AI alignment and broader societal governance of technological development.",
35 "", # output - leave this blank for generation!
36 )
37], return_tensors = "pt").to("cuda")
38
39# Mesurer le temps avant l'inférence
40start_time = time.time()
41#If you want a more detailed output try max_new_tokens=8192
42outputs = model.generate(**inputs, max_new_tokens = 6144, use_cache = True)
43
44# Mesurer le temps après l'inférence
45end_time = time.time()
46
47# Calculer et afficher le temps d'inférence
48inference_time = end_time - start_time
49print(f"Temps d'inférence: {inference_time:.2f} secondes")
50
51# Décodage de la sortie
52result = tokenizer.batch_decode(outputs)
53print(result)