mirror of
https://github.com/theroyallab/tabbyAPI.git
synced 2026-04-29 02:31:48 +00:00
Multimodal: Fix memory leak with MMEmbeddings
On a basic python class, class attributes are handled by reference, meaning that every instance of embeddings would attach to that reference and allocate more memory. Switch to a Pydantic class and factory methods when instantiating. Signed-off-by: kingbri <8082010+kingbri1@users.noreply.github.com>
This commit is contained in:
@@ -1,20 +1,20 @@
|
|||||||
from typing import List
|
|
||||||
from backends.exllamav2.vision import get_image_embedding
|
from backends.exllamav2.vision import get_image_embedding
|
||||||
from common import model
|
from common import model
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
from pydantic import BaseModel, Field
|
||||||
|
from typing import List
|
||||||
|
|
||||||
from common.optional_dependencies import dependencies
|
from common.optional_dependencies import dependencies
|
||||||
|
|
||||||
if dependencies.exllamav2:
|
if dependencies.exllamav2:
|
||||||
from exllamav2 import ExLlamaV2VisionTower
|
from exllamav2 import ExLlamaV2VisionTower
|
||||||
|
|
||||||
|
class MultimodalEmbeddingWrapper(BaseModel):
|
||||||
class MultimodalEmbeddingWrapper:
|
|
||||||
"""Common multimodal embedding wrapper"""
|
"""Common multimodal embedding wrapper"""
|
||||||
|
|
||||||
type: str = None
|
type: str = None
|
||||||
content: List = []
|
content: list = Field(default_factory=list)
|
||||||
text_alias: List[str] = []
|
text_alias: List[str] = Field(default_factory=list)
|
||||||
|
|
||||||
async def add(self, url: str):
|
async def add(self, url: str):
|
||||||
# Determine the type of vision embedding to use
|
# Determine the type of vision embedding to use
|
||||||
|
|||||||
Reference in New Issue
Block a user