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

feat: Add additional env variables for Machine Learning #15326

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

Conversation

1-tempest
Copy link

@1-tempest 1-tempest commented Jan 14, 2025

Add additional variables to only preload partial models.

MACHINE_LEARNING_PRELOAD__CLIP has been depreciated and replaced with MACHINE_LEARNING_PRELOAD__CLIP__MODEL

MACHINE_LEARNING_PRELOAD__FACIAL_RECOGNITION has been depreciated and replaced with MACHINE_LEARNING_PRELOAD__FACIAL_RECOGNITION__MODEL

@1-tempest 1-tempest requested a review from mertalev as a code owner January 14, 2025 03:43
@github-actions github-actions bot added documentation Improvements or additions to documentation 🧠machine-learning labels Jan 14, 2025
@1-tempest 1-tempest changed the title Add additional env variables for Machine Learning feat: Add additional env variables for Machine Learning Jan 14, 2025
Copy link
Contributor

github-actions bot commented Jan 14, 2025

📖 Documentation deployed to pr-15326.preview.immich.app

from pydantic_settings import BaseSettings, SettingsConfigDict
from rich.console import Console
from rich.logging import RichHandler
from uvicorn import Server
from uvicorn.workers import UvicornWorker


class ClipSettings(BaseModel):
model: str | None = None
Copy link
Contributor

Choose a reason for hiding this comment

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

I've been thinking - this interface assumes the same model name will be used for all parts of a task. This is currently true, but might not hold in the future. I think the other approach of doing MACHINE_LEARNING_PRELOAD__CLIP__TEXTUAL=<model name> etc., while more verbose, will be more future-proof so we don't need to make another breaking change down the line.

Copy link
Author

Choose a reason for hiding this comment

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

That's a fair point. Instead of 3 env variables per model, shall I drop it down to two strings instead of a string and 2 booleans?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good to me!

@@ -76,19 +76,32 @@ async def lifespan(_: FastAPI) -> AsyncGenerator[None, None]:

async def preload_models(preload: PreloadModelData) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add deprecation warnings for the old envs?

Copy link
Author

Choose a reason for hiding this comment

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

I'm not sure how I'd go about that, just as a comment or something more?

Copy link
Contributor

@mertalev mertalev Jan 14, 2025

Choose a reason for hiding this comment

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

You can check if the fallback env is not None and call log.warn saying it's deprecated and you should use X instead.

Copy link
Author

Choose a reason for hiding this comment

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

That makes sense, thanks much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:enhancement documentation Improvements or additions to documentation 🧠machine-learning
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants