(self, checkpoint_dir: str, device: str = "cuda")
| 34 | |
| 35 | class InferencePipeline: |
| 36 | def __init__(self, checkpoint_dir: str, device: str = "cuda"): |
| 37 | self.device = torch.device(device if torch.cuda.is_available() else "cpu") |
| 38 | logger.info(f"Initializing model on device: {self.device}") |
| 39 | |
| 40 | # Load the ACEStepPipeline |
| 41 | self.acestep_pipeline = ACEStepPipeline(checkpoint_dir) |
| 42 | self.acestep_pipeline.load_checkpoint(checkpoint_dir) |
| 43 | |
| 44 | # Initialize components |
| 45 | self.transformers = self.acestep_pipeline.ace_step_transformer.float().to(self.device).eval() |
| 46 | self.dcae = self.acestep_pipeline.music_dcae.float().to(self.device).eval() |
| 47 | self.text_encoder_model = self.acestep_pipeline.text_encoder_model.float().to(self.device).eval() |
| 48 | self.text_tokenizer = self.acestep_pipeline.text_tokenizer |
| 49 | |
| 50 | # Ensure no gradients are computed |
| 51 | self.transformers.requires_grad_(False) |
| 52 | self.dcae.requires_grad_(False) |
| 53 | self.text_encoder_model.requires_grad_(False) |
| 54 | |
| 55 | # Initialize scheduler |
| 56 | self.scheduler = FlowMatchEulerDiscreteScheduler( |
| 57 | num_train_timesteps=1000, |
| 58 | shift=3.0, |
| 59 | ) |
| 60 | |
| 61 | def get_text_embeddings(self, texts, device, text_max_length=256): |
| 62 | inputs = self.text_tokenizer( |
nothing calls this directly
no test coverage detected