Prithvik-1 commited on
Commit
3aec4f5
·
verified ·
1 Parent(s): 64ccb77

Upload test_single_sample.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. test_single_sample.py +90 -0
test_single_sample.py ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Quick test script to run inference on a single training sample
4
+ """
5
+
6
+ import json
7
+ import sys
8
+ from pathlib import Path
9
+
10
+ # Add scripts to path
11
+ sys.path.insert(0, str(Path(__file__).parent / "scripts" / "inference"))
12
+
13
+ from inference_codellama import load_local_model, generate_with_local_model
14
+
15
+ def main():
16
+ # Paths
17
+ script_dir = Path(__file__).parent
18
+ model_path = script_dir / "training-outputs" / "codellama-fifo-v1"
19
+ base_model_path = script_dir / "models" / "base-models" / "CodeLlama-7B-Instruct"
20
+ train_dataset = script_dir / "datasets" / "processed" / "split" / "train.jsonl"
21
+
22
+ # Load first sample from training data
23
+ print("=" * 80)
24
+ print("📚 Loading sample from training dataset...")
25
+ print("=" * 80)
26
+
27
+ with open(train_dataset, 'r') as f:
28
+ first_line = f.readline()
29
+ sample = json.loads(first_line)
30
+
31
+ instruction = sample.get("instruction", "")
32
+ expected_response = sample.get("response", "")
33
+
34
+ print("\n📝 Instruction:")
35
+ print("-" * 80)
36
+ print(instruction)
37
+ print("-" * 80)
38
+
39
+ print("\n🎯 Expected Response (first 500 chars):")
40
+ print("-" * 80)
41
+ print(expected_response[:500])
42
+ if len(expected_response) > 500:
43
+ print("...")
44
+ print("-" * 80)
45
+
46
+ # Load model
47
+ print("\n" + "=" * 80)
48
+ print("📦 Loading model...")
49
+ print("=" * 80)
50
+
51
+ model, tokenizer = load_local_model(
52
+ str(model_path),
53
+ str(base_model_path) if base_model_path.exists() else None,
54
+ use_quantization=None,
55
+ merge_weights=False
56
+ )
57
+
58
+ print("✅ Model loaded!\n")
59
+
60
+ # Generate
61
+ print("=" * 80)
62
+ print("🤖 Generating response...")
63
+ print("=" * 80)
64
+ print()
65
+
66
+ try:
67
+ generated_response = generate_with_local_model(
68
+ model,
69
+ tokenizer,
70
+ instruction,
71
+ max_new_tokens=800,
72
+ temperature=0.3,
73
+ stream=False
74
+ )
75
+
76
+ print("\n" + "=" * 80)
77
+ print("✅ GENERATED OUTPUT:")
78
+ print("=" * 80)
79
+ print(generated_response)
80
+ print("=" * 80)
81
+ print(f"\n📊 Output length: {len(generated_response)} characters")
82
+
83
+ except Exception as e:
84
+ print(f"\n❌ Error: {e}")
85
+ import traceback
86
+ traceback.print_exc()
87
+
88
+ if __name__ == "__main__":
89
+ main()
90
+