Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /olaflaitinen_Promethium /src /promethium /workflows /tasks.py
| from celery import Celery | |
| import time | |
| from typing import Dict, Any | |
| from promethium.core.config import get_settings | |
| from promethium.core.logging import get_logger | |
| from promethium.ml.train import PromethiumModule | |
| from promethium.ml.inference import InferenceEngine | |
| from promethium.io.readers import read_segy | |
| settings = get_settings() | |
| logger = get_logger(__name__) | |
| # Initialize Celery | |
| celery_app = Celery( | |
| "promethium_worker", | |
| broker=settings.CELERY_BROKER_URL, | |
| backend=settings.CELERY_RESULT_BACKEND | |
| ) | |
| celery_app.conf.task_track_started = True | |
| def train_model_task(self, training_request: Dict[str, Any]): | |
| """ | |
| Celery task to train a model. | |
| In a real system, this would spin up a subprocess or submit to Slurm/K8s. | |
| Here we run inline for simplicity (assuming Worker has GPU). | |
| """ | |
| job_id = self.request.id | |
| logger.info(f"Starting Training Job {job_id}") | |
| self.update_state(state='RUNNING', meta={'progress': 0}) | |
| try: | |
| # Mock Training Loop for Demo Stability | |
| # Real impl would instantiate Lightning Trainer here using src/promethium/ml/train.py | |
| # trainer = pl.Trainer(...) | |
| # trainer.fit(...) | |
| # Simulating progress | |
| for i in range(0, 100, 10): | |
| time.sleep(1) # Simulating epoch | |
| self.update_state(state='RUNNING', meta={'progress': i}) | |
| logger.info(f"Training Job {job_id} Completed") | |
| return {"status": "success", "model_path": f"/artifacts/{job_id}.pt"} | |
| except Exception as e: | |
| logger.error(f"Training Job {job_id} Failed: {e}") | |
| self.update_state(state='FAILURE', meta={'error': str(e)}) | |
| raise e | |
| def run_inference_task(self, inference_request: Dict[str, Any]): | |
| """ | |
| Celery task for distributed inference. | |
| """ | |
| job_id = self.request.id | |
| logger.info(f"Starting Inference Job {job_id}") | |
| self.update_state(state='RUNNING') | |
| try: | |
| # Instantiate Inference Engine | |
| # input_path = inference_request["input_path"] | |
| # output_path = ... | |
| # engine = InferenceEngine(...) | |
| # engine.run(...) | |
| time.sleep(5) # Mock processing | |
| logger.info(f"Inference Job {job_id} Completed") | |
| return {"status": "success", "output_path": f"/data/outputs/{job_id}.sgy"} | |
| except Exception as e: | |
| logger.error(f"Inference Job {job_id} Failed: {e}") | |
| raise e | |
Xet Storage Details
- Size:
- 2.5 kB
- Xet hash:
- d871a51cc0e6611668cfde8efecd37218169b2e2b4a8c667bb3469a1f70517e3
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.