Skip to content

feat: handle inherited methods in modal classes #240

Description

@hholb

While getting the fairchem models up and running in a modal app, I wanted to do something like this:

import modal

app = modal.App()

app.image = ...

# no decorator here so we don't publish a _BaseModel entrypoint
class _BaseModel():

     @modal.enter()
     def load_model(self):
          # common logic to load model checkpoints
           ...

     @modal.method()
     def run_inference(self):
         # common logic for inference
          ...


@app.cls(...)
class MyModel(_BaseModel):
    # modal picks up the load_model and run_inference methods from the base class
     ...


@app.cls(...)
class MyOtherModel(_BaseModel):
      ...

Modal accepts this kind of setup and handles associating the methods with the subclasses, but our current parsing for modal functions does not recognize the run_inference method as a member of the subclasses.

The backend should recognize two modal classes here, MyModel and MyOtherModel each with a run_inference method as the entrypoint. Currently, the backend recognizes the two model classes, but does not find the run_inference method and returns an empty list of modal functions for each model.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions