@@ -40,20 +40,37 @@ def run_vl_preview_generation(model, tokenizer, model_path, stage_name):
4040 script_dir = os .path .dirname (os .path .abspath (__file__ ))
4141 images_dir = os .path .join (script_dir , "images" )
4242
43+ # Check if images directory exists
44+ if not os .path .exists (images_dir ):
45+ print (f"❌ Warning: Images directory not found at { images_dir } " )
46+ print (" VL preview generation requires sample images to test vision capabilities." )
47+ print (" Skipping VL preview generation." )
48+ return None
49+
4350 # Use single image for VL preview to avoid shape mismatch issues
44- image_files = ["example1a.jpeg" , "example1b.jpeg" ]
51+ image_files = ["example1a.jpeg" , "example1b.jpeg" , "example.jpg" , "test.jpg" , "sample.png" ]
4552 image = None
53+ missing_files = []
4654 for img_file in image_files :
4755 img_path = os .path .join (images_dir , img_file )
4856 if os .path .exists (img_path ):
49- image = Image .open (img_path )
50- print (f" Loaded: { img_file } " )
51- break # Use the first available image
57+ try :
58+ image = Image .open (img_path )
59+ print (f" ✅ Successfully loaded: { img_file } " )
60+ break # Use the first available image
61+ except Exception as e :
62+ print (f" ⚠️ Warning: Could not open { img_file } : { e } " )
63+ missing_files .append (f"{ img_file } (corrupted)" )
5264 else :
53- print ( f" Warning: { img_file } not found" )
65+ missing_files . append ( img_file )
5466
5567 if image is None :
56- print ("No sample images found - skipping VL preview generation" )
68+ print (f"❌ Warning: No valid sample images found in { images_dir } " )
69+ print (f" Searched for: { ', ' .join (image_files )} " )
70+ if missing_files :
71+ print (f" Missing/invalid files: { ', ' .join (missing_files )} " )
72+ print (" VL preview generation requires sample images to test vision capabilities." )
73+ print (" Skipping VL preview generation." )
5774 return None
5875
5976 # Generate response
@@ -66,13 +83,10 @@ def run_vl_preview_generation(model, tokenizer, model_path, stage_name):
6683
6784 print (f"Generating VL response ({ stage_name } )..." )
6885
69- # Try to detect if this is a v1 model ( has chat method) or v2 model (uses generate)
86+ # Try to detect the VL model has chat method or generate method
7087 if hasattr (model , "chat" ):
71- print (" Using v1 model.chat() method..." )
72- # Load image processor for v1 models
7388 image_processor = AutoImageProcessor .from_pretrained (model_path , trust_remote_code = True )
7489
75- # Process single image for v1 models
7690 image_features = image_processor ([image ]) # Pass as list with single image
7791
7892 # Move image features to the same device as the model
@@ -89,11 +103,8 @@ def run_vl_preview_generation(model, tokenizer, model_path, stage_name):
89103 ** image_features ,
90104 )
91105 else :
92- print (" Using v2 model.generate() method..." )
93- # Load processor for v2 models
94106 processor = AutoProcessor .from_pretrained (model_path , trust_remote_code = True )
95107
96- # Create messages in the format expected by v2 models
97108 messages = [
98109 {"role" : "system" , "content" : "/no_think" },
99110 {
@@ -159,7 +170,7 @@ def run_vl_preview_generation(model, tokenizer, model_path, stage_name):
159170
160171
161172def run_text_only_generation (model , tokenizer , question , generation_config , model_path ):
162- """Run text-only generation for VL models, supporting both v1 ( chat) and v2 ( generate) models .
173+ """Run text-only generation for VL models, supporting both chat and generate methods .
163174
164175 Args:
165176 model: The VL model
@@ -173,13 +184,10 @@ def run_text_only_generation(model, tokenizer, question, generation_config, mode
173184 """
174185 try :
175186 if hasattr (model , "chat" ):
176- print (" Using v1 model.chat() method for text-only generation..." )
177187 # Use model.chat with None for images (text-only mode)
178188 response = model .chat (tokenizer , None , question , generation_config , history = None )
179189 return response
180190 else :
181- print (" Using v2 model.generate() method for text-only generation..." )
182- # Load processor for v2 models
183191 processor = AutoProcessor .from_pretrained (model_path , trust_remote_code = True )
184192
185193 # Create text-only messages
0 commit comments