Skip to content

feat: AE-815 Add class based execution - #72

Merged
deanq merged 7 commits into
mainfrom
feat/ae-815-add-cls-exec
Jul 22, 2025
Merged

feat: AE-815 Add class based execution#72
deanq merged 7 commits into
mainfrom
feat/ae-815-add-cls-exec

Conversation

@pandyamarut

@pandyamarut pandyamarut commented Jul 15, 2025

Copy link
Copy Markdown
Contributor

Example:

import asyncio
from tetra_rp import remote, LiveServerless, GpuGroup

gpu_config = LiveServerless(
    gpus=[GpuGroup.AMPERE_16],
    name="basic_vllm_example",
)

@remote(
    resource_config=gpu_config,
    dependencies=["vllm", "torch"],
)
class BasicLLM:
    def __init__(self):
        from vllm import LLM, SamplingParams
        import os
        
        print("Initializing vLLM with Facebook model...")
        
        os.environ["VLLM_USE_V1"] = "0"
        os.environ["VLLM_WORKER_MULTIPROC_METHOD"] = "spawn"
        
        # Very basic vLLM initialization with Facebook's model
        self.llm = LLM(
            model="facebook/opt-125m",
            enforce_eager=True,  # Disable CUDA graphs
            gpu_memory_utilization=0.6,
            max_model_len=1024,
        )
        self.sampling_params = SamplingParams(temperature=0.8, max_tokens=50)
        
        print("vLLM initialized successfully!")
    
    def test_generate(self):
        # Simple test generation
        prompt = "Hello, my name is"
        outputs = self.llm.generate([prompt], self.sampling_params)
        
        return {
            "prompt": prompt,
            "output": outputs[0].outputs[0].text
        }

async def main():
    print("Testing vLLM initialization...")
    
    # Create instance
    llm = BasicLLM()
    
    # Test generation
    result = await llm.test_generate()
    
    print(f"Prompt: {result['prompt']}")
    print(f"Output: {result['output']}")
    print("✅ vLLM test successful!")

if __name__ == "__main__":
    asyncio.run(main())
    

This vLLM example demonstrates the key benefits: the BasicLLM class loads the model once in init(), then the generate() method can be called multiple times with different prompts, all using the same GPU model. The instance persists between calls, maintaining both the loaded model and any internal state, making it essential for production ML services that need both performance and statefulness.

## EXECUTION_FLOW: 

1. Client: llm = BasicLLM("facebook/opt-125m")          # Creates proxy
2. Client: await llm.test_generate(prompts)                  # Triggers remote execution
3. RunPod: Creates new BasicLLM instance                # Only on first call
4. RunPod: BasicLLM.__init__() loads vLLM model        # Expensive (30+ seconds)
5. RunPod: Stores instance in registry                  # For reuse
6. RunPod: BasicLLM.generate() processes prompts       # Fast inference
7. Client: Returns results                              # Response back

Subsequent calls:
8. Client: await llm.test_generate(new_prompts)             # Same proxy
9. RunPod: Finds existing instance in registry         # Instant lookup
10. RunPod: BasicLLM.generate() on same instance       # No model reloading
11. Client: Returns results                             # Fast response`

Signed-off-by: pandyamarut <pandyamarut@gmail.com>
Signed-off-by: pandyamarut <pandyamarut@gmail.com>
Signed-off-by: pandyamarut <pandyamarut@gmail.com>

@deanq deanq left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either write unit and integration tests or write a working tetra-example to flush out any unforeseen bugs

Comment thread src/tetra_rp/client.py
Comment thread src/tetra_rp/execute_class.py Outdated
Comment thread src/tetra_rp/execute_class.py Outdated
Comment on lines +55 to +56
print(f"Warning: Could not extract class code for {cls.__name__}: {e}")
print("Falling back to basic class structure")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log.warning

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pandyamarut It's still using print().

Comment thread src/tetra_rp/execute_class.py Outdated
Comment thread src/tetra_rp/execute_class.py Outdated
Comment thread src/tetra_rp/execute_class.py
Comment thread src/tetra_rp/execute_class.py Outdated
@deanq

deanq commented Jul 18, 2025

Copy link
Copy Markdown
Member

Be sure to run make check after all your changes. You can ignore the mypy warnings. We can address those later. They don't block CI/CD for now.

Signed-off-by: pandyamarut <pandyamarut@gmail.com>
@pandyamarut
pandyamarut requested a review from deanq July 21, 2025 05:39

@deanq deanq left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a tests/integration/test_class_execution_integration.py since these changes are crucial and complex. We want to keep this durable. Some test suggestions I can think of:

  • Test remote class decorator integration
  • Test multiple method calls on the same instance
  • Test class with complex constructor arguments
  • Test error handling in remote class execution

Comment thread tests/unit/test_execute_class.py Outdated
Comment thread src/tetra_rp/execute_class.py Outdated
Comment on lines +55 to +56
print(f"Warning: Could not extract class code for {cls.__name__}: {e}")
print("Falling back to basic class structure")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pandyamarut It's still using print().

@pandyamarut
pandyamarut requested a review from deanq July 22, 2025 05:58
@deanq
deanq merged commit d2a70ad into main Jul 22, 2025
7 checks passed
@deanq
deanq deleted the feat/ae-815-add-cls-exec branch July 22, 2025 17:32
@github-actions github-actions Bot mentioned this pull request Jul 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants