- 
                Notifications
    You must be signed in to change notification settings 
- Fork 77
          Add llm-transpile command with Switch runner and integration tests
          #2078
        
          New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Open
      
      
            hiroyukinakazato-db
  wants to merge
  25
  commits into
  feature/switch-installer-integration
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
feature/llm-transpile
  
      
      
   
  
    
  
  
  
 
  
      
    base: feature/switch-installer-integration
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Changes from 22 commits
      Commits
    
    
            Show all changes
          
          
            25 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      fae9880
              
                feat: add llm-transpile command with Switch integration
              
              
                hiroyukinakazato-db 2ee157f
              
                refactor: encapsulate Switch package path resolution in SwitchDeployment
              
              
                hiroyukinakazato-db b736965
              
                test: update Switch installation tests for refactored interface
              
              
                hiroyukinakazato-db bacd5f6
              
                fix: update error messages to include 'true' flag for install-transpi…
              
              
                hiroyukinakazato-db 21b6629
              
                Merge branch 'main' into feature/llm-transpile
              
              
                hiroyukinakazato-db 81c32e5
              
                fix: exclude wait_for_completion from Switch job parameters
              
              
                hiroyukinakazato-db 13bcc15
              
                chore: update Switch wheel with wait_for_completion fix
              
              
                hiroyukinakazato-db 8dcf8f3
              
                feat: add E2E test for Switch transpiler with environment variable co…
              
              
                hiroyukinakazato-db 83678b8
              
                feat: enhance E2E testing for Switch with resource management and uni…
              
              
                hiroyukinakazato-db ee5c892
              
                chore: merge main into feature/llm-transpile
              
              
                hiroyukinakazato-db ac382d6
              
                Merge branch 'main' into feature/llm-transpile
              
              
                sundarshankar89 4600583
              
                Merge branch 'feature/switch-installer-integration' into feature/llm-…
              
              
                sundarshankar89 7f0eaa4
              
                Rebased from switch installer integration
              
              
                sundarshankar89 0e22abe
              
                Rebased from switch installer integration
              
              
                sundarshankar89 43cc0f5
              
                Intermediate check in
              
              
                sundarshankar89 bb7c3d6
              
                Intermediate check in
              
              
                sundarshankar89 bd70638
              
                Intermediate check in
              
              
                sundarshankar89 0eb1570
              
                Intermediate check in
              
              
                sundarshankar89 9823201
              
                Merge branch 'feature/switch-installer-integration' into feature/llm-…
              
              
                sundarshankar89 eb46f24
              
                initial tests
              
              
                sundarshankar89 c54e68f
              
                Merge branch 'feature/switch-installer-integration' into feature/llm-…
              
              
                sundarshankar89 fab0e87
              
                Merge branch 'feature/switch-installer-integration' into feature/llm-…
              
              
                sundarshankar89 1e10b60
              
                added flag to fail if users use regular transpile after installing sw…
              
              
                sundarshankar89 394ad9d
              
                Merge branch 'feature/switch-installer-integration' into feature/llm-…
              
              
                sundarshankar89 aeff475
              
                Merge branch 'feature/switch-installer-integration' into feature/llm-…
              
              
                sundarshankar89 File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
          Some comments aren't visible on the classic Files Changed page.
        
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -22,3 +22,4 @@ remorph_transpile/ | |
| /linter/src/main/antlr4/library/gen/ | ||
| .databricks-login.json | ||
| .mypy_cache | ||
| .env | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              
        
          
  
    
      
          
            146 changes: 146 additions & 0 deletions
          
          146 
        
  src/databricks/labs/lakebridge/transpiler/switch_runner.py
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| import io | ||
| import logging | ||
| import os | ||
| import random | ||
| import string | ||
| from datetime import datetime, timezone | ||
| from pathlib import Path | ||
|  | ||
| from databricks.labs.blueprint.installation import Installation, RootJsonValue | ||
| from databricks.sdk import WorkspaceClient | ||
|  | ||
| logger = logging.getLogger(__name__) | ||
|  | ||
|  | ||
| class SwitchRunner: | ||
| """Runner for Switch LLM transpilation jobs.""" | ||
|  | ||
| def __init__( | ||
| self, | ||
| ws: WorkspaceClient, | ||
| installation: Installation, | ||
| ): | ||
| self._ws = ws | ||
| self._installation = installation | ||
|  | ||
| def run( | ||
| self, | ||
| volume_input_path: str, | ||
| output_ws_folder: str, | ||
| source_tech: str, | ||
| job_id: int, | ||
| wait_for_completion: bool = False, | ||
| ) -> RootJsonValue: | ||
| """Upload local files to Volume and trigger Switch job.""" | ||
|  | ||
| job_params = self._build_job_parameters( | ||
| input_dir=volume_input_path, | ||
| output_dir=output_ws_folder, | ||
| source_tech=source_tech, | ||
| ) | ||
| logger.info(f"Triggering Switch job with job_id: {job_id}") | ||
|  | ||
| return self._run_job(job_id, job_params, wait_for_completion) | ||
|  | ||
| def upload_to_volume( | ||
| self, | ||
| local_path: Path, | ||
| catalog: str, | ||
| schema: str, | ||
| volume: str, | ||
| ) -> str: | ||
| """Upload local files to UC Volume with unique timestamped path.""" | ||
| now = datetime.now(timezone.utc) | ||
| time_part = now.strftime("%Y%m%d%H%M%S") | ||
| random_part = ''.join(random.choices(string.ascii_lowercase + string.digits, k=4)) | ||
| timestamp_suffix = f"{time_part}_{random_part}" | ||
| volume_base_path = f"/Volumes/{catalog}/{schema}/{volume}" | ||
| volume_input_path = f"{volume_base_path}/input_{timestamp_suffix}" | ||
|  | ||
| logger.info(f"Uploading {local_path} to {volume_input_path}...") | ||
|  | ||
| # File upload | ||
| if local_path.is_file(): | ||
| volume_file_path = f"{volume_input_path}/{local_path.name}" | ||
| with open(local_path, 'rb') as f: | ||
| content = f.read() | ||
| self._ws.files.upload(file_path=volume_file_path, contents=io.BytesIO(content), overwrite=True) | ||
| logger.debug(f"Uploaded: {local_path} -> {volume_file_path}") | ||
|  | ||
| # Directory upload | ||
| else: | ||
| for root, _, files in os.walk(local_path): | ||
| for file in files: | ||
| local_file = Path(root) / file | ||
| relative_path = local_file.relative_to(local_path) | ||
| volume_file_path = f"{volume_input_path}/{relative_path}" | ||
|  | ||
| with open(local_file, 'rb') as f: | ||
| content = f.read() | ||
|  | ||
| self._ws.files.upload(file_path=volume_file_path, contents=io.BytesIO(content), overwrite=True) | ||
| logger.debug(f"Uploaded: {local_file} -> {volume_file_path}") | ||
|  | ||
| logger.info(f"Upload complete: {volume_input_path}") | ||
| return volume_input_path | ||
|  | ||
| def _build_job_parameters( | ||
| self, | ||
| input_dir: str, | ||
| output_dir: str, | ||
| source_tech: str, | ||
| switch_options: dict | None = None, | ||
| ) -> dict[str, str]: | ||
| """Build Switch job parameters.""" | ||
| if switch_options is None: | ||
| switch_options = {} | ||
| return { | ||
| "input_dir": input_dir, | ||
| "output_dir": output_dir, | ||
| "source_tech": source_tech, | ||
| **switch_options, | ||
| } | ||
|  | ||
| def _run_job( | ||
| self, | ||
| job_id: int, | ||
| job_params: dict[str, str], | ||
| wait_for_completion: bool, | ||
| ) -> RootJsonValue: | ||
| """Execute Switch job and return run information.""" | ||
| if wait_for_completion: | ||
| run = self._ws.jobs.run_now_and_wait(job_id, job_parameters=job_params) | ||
|  | ||
| if not run.run_id: | ||
| raise SystemExit(f"Job {job_id} execution failed.") | ||
|  | ||
| job_run_url = f"{self._ws.config.host}/jobs/{job_id}/runs/{run.run_id}" | ||
| logger.info(f"Switch LLM transpilation job completed: {job_run_url}") | ||
|  | ||
| return [ | ||
| { | ||
| "job_id": job_id, | ||
| "run_id": run.run_id, | ||
| "run_url": job_run_url, | ||
| "state": ( | ||
| run.state.life_cycle_state.value if run.state and run.state.life_cycle_state else "UNKNOWN" | ||
| ), | ||
| "result_state": run.state.result_state.value if run.state and run.state.result_state else None, | ||
| } | ||
| ] | ||
|  | ||
| wait = self._ws.jobs.run_now(job_id, job_parameters=job_params) | ||
|  | ||
| if not wait.run_id: | ||
| raise SystemExit(f"Job {job_id} execution failed.") | ||
|  | ||
| job_run_url = f"{self._ws.config.host}/jobs/{job_id}/runs/{wait.run_id}" | ||
| logger.info(f"Switch LLM transpilation job started: {job_run_url}") | ||
|  | ||
| return [ | ||
| { | ||
| "job_id": job_id, | ||
| "run_id": wait.run_id, | ||
| "run_url": job_run_url, | ||
| } | ||
| ] | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
      
      Oops, something went wrong.
        
    
  
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the command is llm-transpile
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will modify this.