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

Refactoring more GenerateService functions across shortfin apps #1010

Open
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

KyleHerndon
Copy link
Contributor

No description provided.

@KyleHerndon KyleHerndon changed the title Finish refactoring GenerateService across shortfin apps Refactoring more GenerateService functions across shortfin apps Mar 3, 2025
Base automatically changed from shortfin-refactor-1 to main March 3, 2025 22:01
Copy link
Contributor

@sogartar sogartar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing that I find very useful is having ubiquitous type hints. It makes the code much more readable and code navigation/exploration is improved.

Comment on lines +177 to +181
self.name = None
self.model_params = None
self.prog_isolation = None
self.inference_programs = {}
self.inference_functions = {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add type hints on these?

self.show_progress = False

# Worker and fiber configuration
self.workers = []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type hint.

*self.inference_modules[component],
]

def create_program(self, modules, devices, isolation=None, trace_execution=None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add type hints?

trace_execution=trace_execution,
)

def create_worker(self, device, index):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type hints on the arguments as well on the return.

Comment on lines +66 to +67
inference_programs: dict[int, dict[str, sf.Program]]
inference_functions: dict[int, dict[str, sf.ProgramFunction]]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the point of this declarations? They are now moved to the base class.

Comment on lines +34 to +35
inference_programs: dict[int, dict[str, sf.Program]]
inference_functions: dict[int, dict[str, sf.ProgramFunction]]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are now part of the GenerateService base.

Comment on lines +187 to +189
self.workers_per_device = 1
self.fibers_per_device = 1
self.fibers_per_worker = 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be cleaner if these were arguments to the __init__ function.

"""Base class for shortfin service implementations."""

def __init__(self, sysman: SystemManager):
"""Initialize base service attributes."""
self.sysman = sysman
self.inference_parameters: dict[str, list[sf.BaseProgramParameters]] = {}
self.inference_modules: dict[str, list[sf.ProgramModule]] = {}
self.name = None
self.model_params = None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be an __init__ argument. Generally, the base class should be responsible for initialization of its members.

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

Successfully merging this pull request may close these issues.

2 participants