From 5060c3a7fe0765be23d9436a877045e82d04567f Mon Sep 17 00:00:00 2001 From: ChengjieLi Date: Tue, 12 Mar 2024 18:25:06 +0800 Subject: [PATCH 1/2] fix --- xinference/model/image/__init__.py | 20 ++++++++++++------- xinference/model/image/core.py | 18 ++++++++++++++++- .../src/scenes/launch_model/embeddingCard.js | 17 +++++----------- .../ui/src/scenes/launch_model/imageCard.js | 17 +++++----------- .../ui/src/scenes/launch_model/rerankCard.js | 17 +++++----------- 5 files changed, 45 insertions(+), 44 deletions(-) diff --git a/xinference/model/image/__init__.py b/xinference/model/image/__init__.py index 2ce50bd6de..0654f93057 100644 --- a/xinference/model/image/__init__.py +++ b/xinference/model/image/__init__.py @@ -18,7 +18,9 @@ from itertools import chain from .core import ( + BUILTIN_IMAGE_MODELS, IMAGE_MODEL_DESCRIPTIONS, + MODELSCOPE_IMAGE_MODELS, ImageModelFamilyV1, generate_image_description, get_cache_status, @@ -29,14 +31,18 @@ _model_spec_modelscope_json = os.path.join( os.path.dirname(__file__), "model_spec_modelscope.json" ) -BUILTIN_IMAGE_MODELS = dict( - (spec["model_name"], ImageModelFamilyV1(**spec)) - for spec in json.load(codecs.open(_model_spec_json, "r", encoding="utf-8")) +BUILTIN_IMAGE_MODELS.update( + dict( + (spec["model_name"], ImageModelFamilyV1(**spec)) + for spec in json.load(codecs.open(_model_spec_json, "r", encoding="utf-8")) + ) ) -MODELSCOPE_IMAGE_MODELS = dict( - (spec["model_name"], ImageModelFamilyV1(**spec)) - for spec in json.load( - codecs.open(_model_spec_modelscope_json, "r", encoding="utf-8") +MODELSCOPE_IMAGE_MODELS.update( + dict( + (spec["model_name"], ImageModelFamilyV1(**spec)) + for spec in json.load( + codecs.open(_model_spec_modelscope_json, "r", encoding="utf-8") + ) ) ) diff --git a/xinference/model/image/core.py b/xinference/model/image/core.py index 7088c5a00f..e19a2b839c 100644 --- a/xinference/model/image/core.py +++ b/xinference/model/image/core.py @@ -27,6 +27,8 @@ logger = logging.getLogger(__name__) IMAGE_MODEL_DESCRIPTIONS: Dict[str, List[Dict]] = defaultdict(list) +BUILTIN_IMAGE_MODELS: Dict[str, "ImageModelFamilyV1"] = {} +MODELSCOPE_IMAGE_MODELS: Dict[str, "ImageModelFamilyV1"] = {} def get_image_model_descriptions(): @@ -151,7 +153,21 @@ def get_cache_status( ) -> bool: cache_dir = get_cache_dir(model_spec) meta_path = os.path.join(cache_dir, "__valid_download") - return valid_model_revision(meta_path, model_spec.model_revision) + + model_name = model_spec.model_name + if model_name in BUILTIN_IMAGE_MODELS and model_name in MODELSCOPE_IMAGE_MODELS: + hf_spec = BUILTIN_IMAGE_MODELS[model_name] + ms_spec = MODELSCOPE_IMAGE_MODELS[model_name] + + return any( + [ + valid_model_revision(meta_path, hf_spec.model_revision), + valid_model_revision(meta_path, ms_spec.model_revision), + ] + ) + else: # Usually for UT + logger.warning(f"Cannot find builtin image model spec: {model_name}") + return valid_model_revision(meta_path, model_spec.model_revision) def create_image_model_instance( diff --git a/xinference/web/ui/src/scenes/launch_model/embeddingCard.js b/xinference/web/ui/src/scenes/launch_model/embeddingCard.js index 46b4dcdd8a..33e7d1e133 100644 --- a/xinference/web/ui/src/scenes/launch_model/embeddingCard.js +++ b/xinference/web/ui/src/scenes/launch_model/embeddingCard.js @@ -1,17 +1,10 @@ -import { RocketLaunchOutlined, UndoOutlined } from '@mui/icons-material' +import {RocketLaunchOutlined, UndoOutlined} from '@mui/icons-material' import DeleteIcon from '@mui/icons-material/Delete' -import { - Box, - Chip, - CircularProgress, - FormControl, - Stack, - TextField, -} from '@mui/material' +import {Box, Chip, CircularProgress, FormControl, Stack, TextField,} from '@mui/material' import IconButton from '@mui/material/IconButton' -import React, { useContext, useEffect, useState } from 'react' +import React, {useContext, useEffect, useState} from 'react' -import { ApiContext } from '../../components/apiContext' +import {ApiContext} from '../../components/apiContext' import fetcher from '../../components/fetcher' const CARD_HEIGHT = 270 @@ -259,7 +252,7 @@ const EmbeddingCard = ({ }) })()} {(() => { - if (modelData.is_cached) { + if (modelData.cache_status) { return } })()} diff --git a/xinference/web/ui/src/scenes/launch_model/imageCard.js b/xinference/web/ui/src/scenes/launch_model/imageCard.js index f30d3830cb..e57c30e45f 100644 --- a/xinference/web/ui/src/scenes/launch_model/imageCard.js +++ b/xinference/web/ui/src/scenes/launch_model/imageCard.js @@ -1,17 +1,10 @@ -import { RocketLaunchOutlined, UndoOutlined } from '@mui/icons-material' +import {RocketLaunchOutlined, UndoOutlined} from '@mui/icons-material' import DeleteIcon from '@mui/icons-material/Delete' -import { - Box, - Chip, - CircularProgress, - FormControl, - Stack, - TextField, -} from '@mui/material' +import {Box, Chip, CircularProgress, FormControl, Stack, TextField,} from '@mui/material' import IconButton from '@mui/material/IconButton' -import React, { useContext, useEffect, useState } from 'react' +import React, {useContext, useEffect, useState} from 'react' -import { ApiContext } from '../../components/apiContext' +import {ApiContext} from '../../components/apiContext' import fetcher from '../../components/fetcher' const CARD_HEIGHT = 270 @@ -249,7 +242,7 @@ const ImageCard = ({ ) })()} {(() => { - if (modelData.is_cached) { + if (modelData.cache_status) { return } })()} diff --git a/xinference/web/ui/src/scenes/launch_model/rerankCard.js b/xinference/web/ui/src/scenes/launch_model/rerankCard.js index 51cf6558d7..47500b2455 100644 --- a/xinference/web/ui/src/scenes/launch_model/rerankCard.js +++ b/xinference/web/ui/src/scenes/launch_model/rerankCard.js @@ -1,17 +1,10 @@ -import { RocketLaunchOutlined, UndoOutlined } from '@mui/icons-material' +import {RocketLaunchOutlined, UndoOutlined} from '@mui/icons-material' import DeleteIcon from '@mui/icons-material/Delete' -import { - Box, - Chip, - CircularProgress, - FormControl, - Stack, - TextField, -} from '@mui/material' +import {Box, Chip, CircularProgress, FormControl, Stack, TextField,} from '@mui/material' import IconButton from '@mui/material/IconButton' -import React, { useContext, useEffect, useState } from 'react' +import React, {useContext, useEffect, useState} from 'react' -import { ApiContext } from '../../components/apiContext' +import {ApiContext} from '../../components/apiContext' import fetcher from '../../components/fetcher' const CARD_HEIGHT = 270 @@ -245,7 +238,7 @@ const RerankCard = ({ }) })()} {(() => { - if (modelData.is_cached) { + if (modelData.cache_status) { return } })()} From 8339d1108894e1147e44fecc116bec682b8c87ca Mon Sep 17 00:00:00 2001 From: ChengjieLi Date: Tue, 12 Mar 2024 18:26:07 +0800 Subject: [PATCH 2/2] fix --- .../ui/src/scenes/launch_model/embeddingCard.js | 15 +++++++++++---- .../web/ui/src/scenes/launch_model/imageCard.js | 15 +++++++++++---- .../web/ui/src/scenes/launch_model/rerankCard.js | 15 +++++++++++---- 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/xinference/web/ui/src/scenes/launch_model/embeddingCard.js b/xinference/web/ui/src/scenes/launch_model/embeddingCard.js index 33e7d1e133..49abdd27d1 100644 --- a/xinference/web/ui/src/scenes/launch_model/embeddingCard.js +++ b/xinference/web/ui/src/scenes/launch_model/embeddingCard.js @@ -1,10 +1,17 @@ -import {RocketLaunchOutlined, UndoOutlined} from '@mui/icons-material' +import { RocketLaunchOutlined, UndoOutlined } from '@mui/icons-material' import DeleteIcon from '@mui/icons-material/Delete' -import {Box, Chip, CircularProgress, FormControl, Stack, TextField,} from '@mui/material' +import { + Box, + Chip, + CircularProgress, + FormControl, + Stack, + TextField, +} from '@mui/material' import IconButton from '@mui/material/IconButton' -import React, {useContext, useEffect, useState} from 'react' +import React, { useContext, useEffect, useState } from 'react' -import {ApiContext} from '../../components/apiContext' +import { ApiContext } from '../../components/apiContext' import fetcher from '../../components/fetcher' const CARD_HEIGHT = 270 diff --git a/xinference/web/ui/src/scenes/launch_model/imageCard.js b/xinference/web/ui/src/scenes/launch_model/imageCard.js index e57c30e45f..5c5c6073bf 100644 --- a/xinference/web/ui/src/scenes/launch_model/imageCard.js +++ b/xinference/web/ui/src/scenes/launch_model/imageCard.js @@ -1,10 +1,17 @@ -import {RocketLaunchOutlined, UndoOutlined} from '@mui/icons-material' +import { RocketLaunchOutlined, UndoOutlined } from '@mui/icons-material' import DeleteIcon from '@mui/icons-material/Delete' -import {Box, Chip, CircularProgress, FormControl, Stack, TextField,} from '@mui/material' +import { + Box, + Chip, + CircularProgress, + FormControl, + Stack, + TextField, +} from '@mui/material' import IconButton from '@mui/material/IconButton' -import React, {useContext, useEffect, useState} from 'react' +import React, { useContext, useEffect, useState } from 'react' -import {ApiContext} from '../../components/apiContext' +import { ApiContext } from '../../components/apiContext' import fetcher from '../../components/fetcher' const CARD_HEIGHT = 270 diff --git a/xinference/web/ui/src/scenes/launch_model/rerankCard.js b/xinference/web/ui/src/scenes/launch_model/rerankCard.js index 47500b2455..9d56f92029 100644 --- a/xinference/web/ui/src/scenes/launch_model/rerankCard.js +++ b/xinference/web/ui/src/scenes/launch_model/rerankCard.js @@ -1,10 +1,17 @@ -import {RocketLaunchOutlined, UndoOutlined} from '@mui/icons-material' +import { RocketLaunchOutlined, UndoOutlined } from '@mui/icons-material' import DeleteIcon from '@mui/icons-material/Delete' -import {Box, Chip, CircularProgress, FormControl, Stack, TextField,} from '@mui/material' +import { + Box, + Chip, + CircularProgress, + FormControl, + Stack, + TextField, +} from '@mui/material' import IconButton from '@mui/material/IconButton' -import React, {useContext, useEffect, useState} from 'react' +import React, { useContext, useEffect, useState } from 'react' -import {ApiContext} from '../../components/apiContext' +import { ApiContext } from '../../components/apiContext' import fetcher from '../../components/fetcher' const CARD_HEIGHT = 270