File size: 3,104 Bytes
7a0c684
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
"""

Main script for running multi-modal inference using Helium framework.

Example usage for end users.

"""
import os
from inference_runner import InferenceRunner

def run_inference_example():
    """Example showing how to use the inference runner"""
    
    # Path to your model checkpoint
    MODEL_PATH = os.path.join(os.path.dirname(__file__), "checkpoints/model")
    
    # Initialize the inference runner
    print("Initializing inference runner...")
    runner = InferenceRunner(
        model_path=MODEL_PATH,
        device_id="vgpu0",  # Use first virtual GPU
        batch_size=4,       # Process 4 items at once
        cache_dir="cache"   # Cache results here
    )
    
    try:
        # Example 1: Single inference with text only
        print("\nRunning text-only inference...")
        result = runner(text="Analyze this sentence.")
        print("Text features shape:", result["text_features"].shape)
        
        # Example 2: Multi-modal inference
        print("\nRunning multi-modal inference...")
        result = runner(
            text="Describe this image and sound:",
            image_path="samples/scene.jpg",
            audio_path="samples/audio.wav"
        )
        print("Available features:", list(result.keys()))
        
        # Example 3: Batch processing
        print("\nProcessing batch...")
        texts = [f"Sample text {i}" for i in range(3)]
        images = ["samples/img1.jpg", "samples/img2.jpg", "samples/img3.jpg"]
        
        for text, img in zip(texts, images):
            runner.add_to_batch(text=text, image_path=img)
            
        batch_result = runner.process_batch()
        print("Batch processing complete. Output shapes:")
        for key, value in batch_result.items():
            print(f"  {key}: {value.shape}")
            
        # Example 4: Generate from multi-modal context
        print("\nGenerating text from multi-modal context...")
        generated = runner.generate_from_context(
            context_text="What's happening in this scene?",
            context_image="samples/scene.jpg",
            context_audio="samples/ambient.wav",
            max_length=50
        )
        print("Generated sequence shape:", generated.shape)
        
    finally:
        # Always cleanup
        print("\nCleaning up resources...")
        runner.cleanup()
        
def main():
    """Main entry point"""
    try:
        run_inference_example()
        print("\nInference completed successfully!")
        
    except FileNotFoundError as e:
        print(f"\nError: Required file not found: {e}")
        print("Please make sure all model files and samples are in the correct location.")
        
    except ValueError as e:
        print(f"\nError: Invalid input: {e}")
        print("Please check your input values and formats.")
        
    except Exception as e:
        print(f"\nUnexpected error: {e}")
        print("If this persists, please check the logs or contact support.")

if __name__ == "__main__":
    main()