Skip to content
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

does service streamer support cpu deploy? #93

Open
zhanghaoie opened this issue Feb 11, 2022 · 1 comment
Open

does service streamer support cpu deploy? #93

zhanghaoie opened this issue Feb 11, 2022 · 1 comment

Comments

@zhanghaoie
Copy link

No description provided.

@rapidrabbit76
Copy link

I'm doing batch inference on CPU in combination with Fastapi.
It works fine.

# env.DEVICE is CPU 

class MyModelManager(ManagedModel):
    def init_model(self):
        classifier = torch.jit.load(
            env.MODEL_PATH, map_location="cpu"
        )
        self.classifier = classifier.eval().to(env.DEVICE)
        logger.info("model init Done")

    @torch.inference_mode()
    def predict(self, inputs: T.List[torch.Tensor]) -> T.List[torch.Tensor]:
        logger.info(f"batch size: {len(inputs)}")
        results = []
        try:
            batch = torch.cat(inputs, 0).to(env.DEVICE)
            print(batch.shape)
            outputs = self.classifier(batch)
            outputs = torch.sigmoid(outputs)
            outputs = outputs.cpu()
            results = [output for output in outputs]
        except Exception as e:
            logger.error(f"Error {self.__class__.__name__}: {e}")
        return results

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

No branches or pull requests

2 participants