zodiac.providers.constants

  1# SPDX-License-Identifier: MPL-2.0 AND LicenseRef-Commons-Clause-License-Condition-1.0
  2# <!-- // /*  d a r k s h a p e s */ -->
  3
  4
  5# pylint:disable=no-name-in-module
  6
  7import os
  8from enum import Enum
  9from typing import Annotated, Callable, List, Optional, Union
 10
 11from nnll.configure.init_gpu import first_available
 12from nnll.mir.json_cache import TEMPLATE_PATH_NAMED, VERSIONS_PATH_NAMED, JSONCache
 13from nnll.mir.maid import MIRDatabase
 14from nnll.monitor.file import dbuq
 15from pydantic import BaseModel, Field
 16from transformers.pipelines import PIPELINE_REGISTRY
 17
 18MIR_DB = MIRDatabase()
 19CUETYPE_PATH_NAMED = os.path.join(os.path.dirname(__file__), "cuetype.json")
 20CUETYPE_CONFIG = JSONCache(CUETYPE_PATH_NAMED)
 21TEMPLATE_CONFIG = JSONCache(TEMPLATE_PATH_NAMED)
 22VERSIONS_DATA = JSONCache(VERSIONS_PATH_NAMED)
 23VERSIONS_DATA._load_cache()
 24VERSIONS_CONFIG = VERSIONS_DATA._cache
 25
 26
 27def check_host(api_name: str, api_url: str) -> bool:
 28    """Perform network test to ensure a host server is running\n
 29    :param api_name: Type of host API
 30    :param api_url: The (default) configuration data for that API
 31    :return: Whether the server is up or not
 32    """
 33
 34    from json.decoder import JSONDecodeError
 35
 36    import httpcore
 37    import httpx
 38    import requests
 39    from openai import APIConnectionError, APIStatusError, APITimeoutError  # , JSONDecodeError,
 40    from urllib3.exceptions import MaxRetryError, NewConnectionError
 41
 42    if api_name == "LM_STUDIO":
 43        from lmstudio import APIConnectionError, APIStatusError, APITimeoutError, JSONDecodeError
 44    try:
 45        dbuq(api_url)
 46        request = requests.get(api_url, timeout=(1, 1))
 47        if request is not None:
 48            dbuq(vars(request))
 49            if hasattr(request, "status_code"):
 50                status = request.status_code
 51                dbuq(status)
 52            if (hasattr(request, "ok") and request.ok) or (hasattr(request, "reason") and request.reason == "OK"):
 53                dbuq(f"Available {api_name}")
 54                return True
 55            elif hasattr(request, "json"):
 56                status = request.json()
 57                if status.get("result") == "OK":
 58                    dbuq(f"Available {api_name}")
 59                    return True
 60            request.raise_for_status()
 61            requests.HTTPError()
 62    except (
 63        APIConnectionError,
 64        APITimeoutError,
 65        APIStatusError,
 66        requests.exceptions.InvalidURL,
 67        requests.exceptions.ConnectionError,
 68        requests.adapters.ConnectionError,
 69        requests.HTTPError,
 70        httpcore.ConnectError,
 71        httpx.ConnectError,
 72        ConnectionRefusedError,
 73        MaxRetryError,
 74        NewConnectionError,
 75        TimeoutError,
 76        JSONDecodeError,
 77        OSError,
 78        RuntimeError,
 79        ConnectionError,
 80    ) as error_log:
 81        dbuq(error_log)
 82    return False
 83
 84
 85@CUETYPE_CONFIG.decorator
 86def has_api(api_name: str, data: dict = None) -> bool:
 87    """Check available modules, try to import dynamically.\n
 88    True for successful import, else False\n
 89
 90    :param api_name: Constant name for API
 91    :param _data: filled by config decorator, ignore, defaults to None
 92    :return: Package availability or `check_host` for servers; boolean result
 93    :rtype: bool
 94    """
 95    from importlib import import_module
 96    from json.decoder import JSONDecodeError
 97
 98    hosted_apis = ["OLLAMA", "LM_STUDIO", "LLAMAFILE", "VLLM"]  # , "CORTEX" ] #became jan
 99    try:
100        api_data = data.get(api_name, {"module": api_name.lower()})  # pylint: disable=unsubscriptable-object
101    except JSONDecodeError as error_log:
102        dbuq(error_log)
103        return False
104    try:
105        module = import_module(api_data.get("module"))
106        if module:
107            if api_name not in hosted_apis:
108                return True
109            else:
110                dbuq(api_data.get("api_url"))
111                url = api_data.get("api_url")
112                if url:
113                    return check_host(api_name, url)
114    except (UnboundLocalError, ImportError, ModuleNotFoundError, JSONDecodeError) as error_log:
115        dbuq(error_log)
116    dbuq("|Ignorable| Source unavailable:", f"{api_name}")
117    return False
118
119
120show_all_docstring = ":param _show_all(): Show all POSSIBLE API types of a given class"
121show_available_docstring = ":param _show_available(): Show all AVAILABLE API types of a given class"
122check_type_docstring = ":param _check_type: Check for a SINGLE API availability"
123
124base_enum_docstring = f"""{show_all_docstring}{show_available_docstring}{check_type_docstring}"""
125
126
127class BaseEnum(Enum):
128    f"""{base_enum_docstring}"""
129
130    @classmethod
131    def show_all(cls) -> List:
132        """Show all POSSIBLE API types of a given class"""
133        return [x for x, y in cls.__members__.items()]
134
135    @classmethod
136    def show_available(cls) -> bool:
137        """Show all AVAILABLE API types of a given class"""
138        return [library.value[1] for library in list(cls) if library.value[0] is True]
139
140    @classmethod
141    def check_type(cls, type_name: str) -> bool:
142        """Check for a SINGLE API availability"""
143        type_name = type_name.upper()
144        return has_api(type_name)
145
146
147class CueType(BaseEnum):
148    f"""Model Provider constants\n
149    Caches and servers\n
150    <NAME: (Availability, IMPORT_NAME)>{base_enum_docstring}
151    {base_enum_docstring}"""
152
153    # Dfferentiation of boolean conditions
154    # GIVEN : The state of all provider modules & servers are marked at launch
155
156    HUB: tuple = (has_api("HUB"), "HUB")
157    KAGGLE: tuple = (has_api("KAGGLE"), "KAGGLE")
158    LLAMAFILE: tuple = (has_api("LLAMAFILE"), "LLAMAFILE")
159    LM_STUDIO: tuple = (has_api("LM_STUDIO"), "LM_STUDIO")
160    MLX_AUDIO: tuple = (has_api("MLX_AUDIO"), "MLX_AUDIO")
161    OLLAMA: tuple = (has_api("OLLAMA"), "OLLAMA")
162    VLLM: tuple = (has_api("VLLM"), "VLLM")
163
164
165example_str = ("function_name", "import.function_name")
166
167
168class PkgType(BaseEnum):
169    """Package dependency constants
170    Collected info from hub model tags and dependencies
171    <NAME: (Availability, IMPORT_NAME, [Github repositories*]
172    *if applicable, otherwise IMPORT_NAME is pip package
173    NOTE: NAME is colloquial and does not always match IMPORT_NAME>"""
174
175    AUDIOGEN: tuple = (has_api("AUDIOCRAFT"), "AUDIOCRAFT", ["exdysa/facebookresearch-audiocraft-revamp"])  # this fork supports mps
176    BAGEL: tuple = (has_api("BAGEL"), "BAGEL", ["bytedance-seed/BAGEL"])
177    BITNET: tuple = (has_api("BITNET"), "BITNET", ["microsoft/BitNet"])
178    BITSANDBYTES: tuple = (has_api("BITSANDBYTES"), "BITSANDBYTES", [])  # bitsandbytes-foundation/bitsandbytes
179    DFLOAT11: tuple = (has_api("DFLOAT11"), "DFLOAT11", ["LeanModels/DFloat11"])
180    DIFFUSERS: tuple = (has_api("DIFFUSERS"), "DIFFUSERS", [])
181    EXLLAMAV2: tuple = (has_api("EXLLAMAV2"), "EXLLAMAV2", [])  # turboderp-org/exllamav2
182    F_LITE: tuple = (has_api("F_LITE"), "F_LITE", ["fal-ai/f-lite"])
183    HIDIFFUSION: tuple = (has_api("HIDIFFUSION"), "HIDIFFUSION", ["megvii-research/HiDiffusion"])
184    IMAGE_GEN_AUX: tuple = (has_api("IMAGE_GEN_AUX"), "IMAGE_GEN_AUX", ["huggingface/image_gen_aux"])
185    JAX: tuple = (has_api("JAX"), "JAX", [])
186    KERAS: tuple = (has_api("KERAS"), "KERAS", [])
187    LLAMA: tuple = (has_api("LLAMA_CPP"), "LLAMA_CPP", [])
188    LUMINA_MGPT: tuple = (has_api("INFERENCE_SOLVER"), "INFERENCE_SOLVER", ["Alpha-VLLM/Lumina-mGPT"])
189    LUMINA_MGPT2: tuple = (has_api("INFERENCE_SOLVER"), "INFERENCE_SOLVER", ["Alpha-VLLM/Lumina-mGPT-2.0"])
190    MFLUX: tuple = (has_api("MFLUX"), "MFLUX", [])  # "filipstrand/mflux"
191    MLX_AUDIO: tuple = (CueType.check_type("MLX_AUDIO"), "MLX_AUDIO", [])  # Blaizzy/mlx-audio
192    MLX_CHROMA: tuple = (has_api("CHROMA"), "CHROMA", ["exdysa/jack813-mlx-chroma"])
193    MLX_LM: tuple = (has_api("MLX_LM"), "MLX_LM", [])  # "ml-explore/mlx-lm"
194    MLX_VLM: tuple = (has_api("MLX_VLM"), "MLX_VLM", [])  # Blaizzy/mlx-vlm
195    MLX: tuple = (has_api("MLX_LM"), "MLX", [])
196    ONNX: tuple = (has_api("ONNX"), "ONNX", ["ONNX"])
197    ORPHEUS_TTS: tuple = (has_api("ORPHEUS_TTS"), "ORPHEUS_TTS", ["canopyai/Orpheus-TTS"])
198    OUTETTS: tuple = (has_api("OUTETTS"), "OUTETTS", ["edwko/OuteTTS"])
199    PARLER_TTS: tuple = (has_api("PARLER_TTS"), "PARLER_TTS", ["huggingface/parler-tts"])
200    PLEIAS: tuple = (has_api("PLEIAS"), "PLEIAS", ["exdysa/Pleias-Pleias-RAG-Library"])  # bypasses vllm for macos to avoid requiring gcc/AVIX
201    SENTENCE_TRANSFORMERS: tuple = (has_api("SENTENCE_TRANSFORMERS"), "SENTENCE_TRANSFORMERS", [])  # UKPLab/sentence-transformers
202    SHOW_O: tuple = (has_api("SHOW_O"), "SHOW_O", ["showlab/show-o"])
203    SPANDREL_EXTRA_ARCHES: tuple = (has_api("SPANDREL_EXTRA_ARCHES"), "SPANDREL_EXTRA_ARCHES", [])
204    SPANDREL: tuple = (has_api("SPANDREL"), "SPANDREL", [])
205    SVDQUANT: tuple = (has_api("NUNCHAKU"), "NUNCHAKU", ["mit-han-lab/nunchaku"])
206    TENSORFLOW: tuple = (has_api("TENSORFLOW"), "TENSORFLOW", [])
207    TORCH: tuple = (has_api("TORCH"), "TORCH", [])  # Possible that torch is NOT needed (mlx_lm, or some other unforeseen future )
208    TORCHAUDIO: tuple = (has_api("TORCHAUDIO"), "TORCHAUDIO", [])
209    TORCHVISION: tuple = (has_api("TORCHVISION"), "TORCHVISION", [])
210    TRANSFORMERS: tuple = (has_api("TRANSFORMERS"), "TRANSFORMERS", [])
211    VLLM: tuple = (CueType.check_type("VLLM"), "VLLM", [])
212
213
214class ChipType(Enum):
215    f"""Device constants\n
216    CUDA, MPS, XPU, MTIA [Supported PkgTypes]\n
217    {base_enum_docstring}"""
218
219    def __call__(cls):
220        cls.initialie_device()
221
222    @classmethod
223    def initialize_device(cls) -> None:
224        chip_types = [
225            (
226                "CUDA",
227                [
228                    PkgType.BAGEL,
229                    PkgType.BITSANDBYTES,
230                    PkgType.DFLOAT11,
231                    PkgType.EXLLAMAV2,
232                    PkgType.F_LITE,
233                    PkgType.LUMINA_MGPT,
234                    PkgType.ORPHEUS_TTS,
235                    PkgType.OUTETTS,
236                    PkgType.VLLM,
237                ],
238            ),
239            ("MPS", [PkgType.MFLUX, PkgType.MLX_AUDIO, PkgType.MLX_LM, PkgType.BAGEL]),
240            ("XPU", []),
241            ("MTIA", []),
242        ]
243        cls._device = first_available(assign=True, init=True, clean=True)  # pylint:disable=no-member, protected-access
244        if hasattr(cls._device, "type"):
245            gpu = cls._device.type
246        else:
247            gpu = ""
248        for name, pkg_type in chip_types:
249            setattr(cls, name, (name.lower() in gpu, name, pkg_type))
250        setattr(
251            cls,
252            "CPU",
253            (
254                True,
255                "CPU",
256                [
257                    PkgType.AUDIOGEN,
258                    PkgType.PARLER_TTS,
259                    PkgType.LLAMA,
260                    PkgType.HIDIFFUSION,
261                    PkgType.SENTENCE_TRANSFORMERS,
262                    PkgType.DIFFUSERS,
263                    PkgType.TRANSFORMERS,
264                    PkgType.TORCH,
265                ],
266            ),
267        )
268
269    @classmethod
270    def _show_all(cls) -> List[str]:
271        """Show all POSSIBLE processor types"""
272        atypes = [atype for atype in cls.__dict__ if "_" not in atype]
273        return atypes
274
275    @classmethod
276    def _show_ready(cls, api_name: Optional[str] = None) -> Union[List[str], bool]:
277        """Show all READY devices.\n
278        If api_name is provided, checks if the specific API is ready.
279        :param api_name: Boolean check for the specific API by name, defaults to None
280        :return: `bool` or list of ready devices
281        """
282        atypes = cls._show_all()
283        if api_name:
284            return api_name.upper() in [x for x in atypes if getattr(cls, x)[0]]
285        return [getattr(cls, x) for x in atypes if getattr(cls, x)[0] is True]
286
287    @classmethod
288    def _show_pkgs(cls) -> Union[List[PkgType], str]:
289        """Return compatible PkgTypes for all available chipsets\n
290        If no chipsets are detected, returns onlyCPU compatibility options\n
291        :return: `PkgType`s for the available processors including CPU
292        """
293        pkg_names = getattr(cls, "CPU")[-1]
294        atypes = cls._show_ready()
295        available = [pkg[1] for pkg in atypes if pkg[0] is True]
296        priority = next(iter(available), "CPU") if available else "CPU"
297        if priority not in [pkg[1] for pkg in cls._show_all() if not pkg[2]] and priority != "CPU":
298            pkg_names = atypes[0][2] + pkg_names
299        return pkg_names
300
301
302ChipType.initialize_device()
303
304
305# class PipeType(Enum):
306#     MFLUX: tuple = (ChipType._show_ready("mps"), PkgType.check_type("MFLUX"), {"mir_tag": "flux"})  # pylint:disable=protected-access
307# MFLUX: tuple = ("MPS" in ChipType._show_ready("mps"), PkgType.MFLUX, {"mir_tag": "flux"})  # pylint:disable=protected-access
308
309
310# Experimental way to abstract/declarify complex task names
311class GenTypeC(BaseModel):
312    """
313    Generative inference types in ***C***-dimensional order\n
314    ***Comprehensiveness***, sorted from 'most involved' to 'least involved'\n
315    The terms define 'artistic' and ambiguous operations\n
316
317    :param clone: Copying identity, voice, exact mirror
318    :param sync: Tone, tempo, color, quality, genre, scale, mood
319    :param translate: A range of comprehensible approximations\n
320    """
321
322    clone: Annotated[Callable | None, Field(default=None)]
323    sync: Annotated[Callable | None, Field(default=None)]
324    translate: Annotated[Callable | None, Field(default=None)]
325
326
327class GenTypeCText(BaseModel):
328    """
329    Generative inference types in ***C***-dimensional order for text operations\n
330    ***Comprehensiveness***, sorted from 'most involved' to 'least involved'\n
331    The terms define 'concrete' and more rigid operations\n
332
333    :param research: Quoting, paraphrasing, and deriving from sources
334    :param chain_of_thought: A performance of processing step-by-step (similar to `reasoning`)
335    :param question_answer: Basic, straightforward responses\n
336    """
337
338    research: Annotated[Optional[Callable | None], Field(default=None, examples=example_str)]
339    chain_of_thought: Annotated[Optional[Callable | None], Field(default=None, examples=example_str)]
340    question_answer: Annotated[Optional[Callable | None], Field(default=None, examples=example_str)]
341
342
343class GenTypeE(BaseModel):
344    """
345    Generative inference operation types in ***E***-dimensional order \n
346    ***Equivalence***, lists sorted from 'highly-similar' to 'loosely correlated.'"\n
347    :param universal: Affecting all conversions
348    :param text: Text-only conversions\n
349
350    ***multimedia generation***
351    ```
352    Y-axis: Detail (Most involved to least involved)
353
354    │                             clone
355    │                 sync
356    │ translate
357
358    +───────────────────────────────────────> X-axis: Equivalence (Loosely correlated to highly similar)
359    ```
360    ***text generation***
361    ```
362    Y-axis: Detail (Most involved to least involved)
363
364    │                           research
365    │             chain-of-thought
366    │ question/answer
367
368    +───────────────────────────────────────> X-axis:  Equivalence (Loosely correlated to highly similar)
369    ```
370
371    This is essentially the translation operation of C types, and the mapping of them to E \n
372
373    An abstract generalization of the set of all multimodal generative synthesis processes\n
374    The sum of each coordinate pair reflects effective compute use\n
375    In this way, both C types and their similarity are translatable, but not 1:1 identical\n
376    Text is allowed to perform all 6 core operations. Other media perform only 3.\n
377    """
378
379    # note: `sync` may have better terms, such as 'harmonize' or 'attune'. `sync` was chosen because it is shorter
380
381    universal: GenTypeC = GenTypeC(clone=None, sync=None, translate=None)
382    text: GenTypeCText = GenTypeCText(research=None, chain_of_thought=None, question_answer=None)
383
384
385# Here, a case could be made that tasks could be determined by filters, rather than graphing
386# This is valid but, it offers no guarantees for difficult logic conditions that can be easily verified by graph algorithms
387# Using graphs also allows us to offload the logic elsewhere
388
389VALID_CONVERSIONS = ["text", "image", "music", "speech", "audio", "video", "3d", "vector_graphic", "upscale_image"]
390VALID_JUNCTIONS = [""]
391
392# note : decide on a way to keep paired tuples and sets together inside config dict
393
394tasks = PIPELINE_REGISTRY.get_supported_tasks() + ["translation_XX_to_YY"]
395
396VALID_TASKS = {  # normalized to lowercase
397    CueType.VLLM: {
398        ("text", "text"): ["text"],
399        ("image", "text"): ["vision"],
400    },
401    CueType.OLLAMA: {
402        ("text", "text"): ["mllama"],
403        ("image", "text"): ["llava", "vllm"],
404    },
405    CueType.LLAMAFILE: {
406        ("text", "text"): ["text"],
407    },
408    CueType.LM_STUDIO: {
409        # ("image", "text"): [("vision", True)],
410        ("text", "text"): ["llm"],
411    },
412    CueType.HUB: {
413        ("image", "image"): [
414            "image-to-image",
415            "inpaint",
416            "inpainting",
417            "depth-to-image",
418            "i2i",
419            "image-to-image",
420            "any-to-any",
421        ],
422        ("text", "image"): ["kolors", "kolorspipeline", "image-generation", "any-to-any", "text-to-image", "chromapipeline"],
423        ("image", "text"): [
424            "image-classification",
425            "image-to-text",
426            "image-text-to-text",
427            "visual-question-answering",
428            "image-captioning",
429            "image-segmentation",
430            "depth-estimation",
431            "image-feature-extraction",
432            "mask-generation",
433            "object-detection",
434            "visual-question-answering",
435            "keypoint-detection",
436            "vllm",
437            "vqa",
438            "vision",
439            "zero-shot-object-detection",
440            "zero-shot-image-classification",
441            "timm",
442            "zero-shot image classification",
443            "any-to-any",
444            "vidore",
445        ],
446        ("image", "video"): ["image-to-video", "i2v", "reference-to-video", "refernce-to-video"],
447        ("video", "text"): ["video-classification"],
448        ("text", "video"): ["video generation", "t2v", "text-to-video", "HunyuanVideoPipeline"],
449        ("text", "text"): [
450            "any-to-any",
451            "named entity recognition",
452            "entity typing",
453            "relation classification",
454            "question answering",
455            "fill-mask",
456            "chat",
457            "conversational",
458            "text-generation",
459            "causal-lm",
460            "text2text-generation",
461            "document-question-answering",
462            "feature-extraction",
463            "question-answering",
464            "sentiment-analysis",
465            "summarization",
466            "table-question-answering",
467            "text-classification",
468            "token-classification",
469            "translation",
470            "zero-shot-classification",
471            "translation_xx_to_yy",
472            "t2t",
473            "chatglm",
474            "exbert",
475        ],
476        ("text", "audio"): ["text-to-audio", "t2a", "any-to-any", "text-to-audio", " musicldmpipeline", "musicgen", "audiocraft", "audiogen", "AudioLDMPipeline", "AudioLDM2Pipeline"],
477        ("audio", "text"): ["zero-shot-audio-classification", "audio-classification", "a2t", "audio-text-to-text", "any-to-any"],
478        ("text", "speech"): [
479            "text-to-speech",
480            "tts",
481            "any-to-any",
482            "annotation",
483        ],
484        ("speech", "text"): [
485            "speech-to-text",
486            "speech",
487            "speech-translation",
488            "speech-summarization",
489            "automatic-speech-recognition",
490            "dictation",
491            "stt",
492            "any-to-any",
493            "hf-asr-leaderboard",
494        ],
495    },
496    CueType.KAGGLE: {
497        ("text", "text"): ["text"],
498    },
499    # CueType.CORTEX: {
500    #     ("text", "text"): ["text"],
501    # },
502}
MIR_DB = <nnll.mir.maid.MIRDatabase object>
CUETYPE_PATH_NAMED = '/Users/e6d64/Documents/GitHub/darkshapes/zodiac/zodiac/providers/cuetype.json'
CUETYPE_CONFIG = <nnll.mir.json_cache.JSONCache object>
TEMPLATE_CONFIG = <nnll.mir.json_cache.JSONCache object>
VERSIONS_DATA = <nnll.mir.json_cache.JSONCache object>
VERSIONS_CONFIG = {'semantic': ['-?\\d+[bBmMkK]', '-?v\\d+', '(?<=\\d)[.-](?=\\d)', '-prior$', '-diffusers$', '-large$', '-medium$'], 'suffixes': ['-\\d{1,2}[bBmMkK]', '-\\d[1-9][bBmMkK]', '-v\\d{1,2}', '-\\d{3,}$', '-\\d{4,}.*', '-\\d{4,}[px].*'], 'ignore': ['-xt$', '-box$', '-preview$', '-base.*', '-Tiny$', '-full$', '-mini.*', '-multimodal.*', '-instruct.*']}
def check_host(api_name: str, api_url: str) -> bool:
28def check_host(api_name: str, api_url: str) -> bool:
29    """Perform network test to ensure a host server is running\n
30    :param api_name: Type of host API
31    :param api_url: The (default) configuration data for that API
32    :return: Whether the server is up or not
33    """
34
35    from json.decoder import JSONDecodeError
36
37    import httpcore
38    import httpx
39    import requests
40    from openai import APIConnectionError, APIStatusError, APITimeoutError  # , JSONDecodeError,
41    from urllib3.exceptions import MaxRetryError, NewConnectionError
42
43    if api_name == "LM_STUDIO":
44        from lmstudio import APIConnectionError, APIStatusError, APITimeoutError, JSONDecodeError
45    try:
46        dbuq(api_url)
47        request = requests.get(api_url, timeout=(1, 1))
48        if request is not None:
49            dbuq(vars(request))
50            if hasattr(request, "status_code"):
51                status = request.status_code
52                dbuq(status)
53            if (hasattr(request, "ok") and request.ok) or (hasattr(request, "reason") and request.reason == "OK"):
54                dbuq(f"Available {api_name}")
55                return True
56            elif hasattr(request, "json"):
57                status = request.json()
58                if status.get("result") == "OK":
59                    dbuq(f"Available {api_name}")
60                    return True
61            request.raise_for_status()
62            requests.HTTPError()
63    except (
64        APIConnectionError,
65        APITimeoutError,
66        APIStatusError,
67        requests.exceptions.InvalidURL,
68        requests.exceptions.ConnectionError,
69        requests.adapters.ConnectionError,
70        requests.HTTPError,
71        httpcore.ConnectError,
72        httpx.ConnectError,
73        ConnectionRefusedError,
74        MaxRetryError,
75        NewConnectionError,
76        TimeoutError,
77        JSONDecodeError,
78        OSError,
79        RuntimeError,
80        ConnectionError,
81    ) as error_log:
82        dbuq(error_log)
83    return False

Perform network test to ensure a host server is running

Parameters
  • api_name: Type of host API
  • api_url: The (default) configuration data for that API
Returns

Whether the server is up or not

@CUETYPE_CONFIG.decorator
def has_api(api_name: str, data: dict = None) -> bool:
 86@CUETYPE_CONFIG.decorator
 87def has_api(api_name: str, data: dict = None) -> bool:
 88    """Check available modules, try to import dynamically.\n
 89    True for successful import, else False\n
 90
 91    :param api_name: Constant name for API
 92    :param _data: filled by config decorator, ignore, defaults to None
 93    :return: Package availability or `check_host` for servers; boolean result
 94    :rtype: bool
 95    """
 96    from importlib import import_module
 97    from json.decoder import JSONDecodeError
 98
 99    hosted_apis = ["OLLAMA", "LM_STUDIO", "LLAMAFILE", "VLLM"]  # , "CORTEX" ] #became jan
100    try:
101        api_data = data.get(api_name, {"module": api_name.lower()})  # pylint: disable=unsubscriptable-object
102    except JSONDecodeError as error_log:
103        dbuq(error_log)
104        return False
105    try:
106        module = import_module(api_data.get("module"))
107        if module:
108            if api_name not in hosted_apis:
109                return True
110            else:
111                dbuq(api_data.get("api_url"))
112                url = api_data.get("api_url")
113                if url:
114                    return check_host(api_name, url)
115    except (UnboundLocalError, ImportError, ModuleNotFoundError, JSONDecodeError) as error_log:
116        dbuq(error_log)
117    dbuq("|Ignorable| Source unavailable:", f"{api_name}")
118    return False

Check available modules, try to import dynamically.

True for successful import, else False

Parameters
  • api_name: Constant name for API
  • _data: filled by config decorator, ignore, defaults to None
Returns

Package availability or check_host for servers; boolean result

show_all_docstring = ':param _show_all(): Show all POSSIBLE API types of a given class'
show_available_docstring = ':param _show_available(): Show all AVAILABLE API types of a given class'
check_type_docstring = ':param _check_type: Check for a SINGLE API availability'
base_enum_docstring = ':param _show_all(): Show all POSSIBLE API types of a given class:param _show_available(): Show all AVAILABLE API types of a given class:param _check_type: Check for a SINGLE API availability'
class BaseEnum(enum.Enum):
128class BaseEnum(Enum):
129    f"""{base_enum_docstring}"""
130
131    @classmethod
132    def show_all(cls) -> List:
133        """Show all POSSIBLE API types of a given class"""
134        return [x for x, y in cls.__members__.items()]
135
136    @classmethod
137    def show_available(cls) -> bool:
138        """Show all AVAILABLE API types of a given class"""
139        return [library.value[1] for library in list(cls) if library.value[0] is True]
140
141    @classmethod
142    def check_type(cls, type_name: str) -> bool:
143        """Check for a SINGLE API availability"""
144        type_name = type_name.upper()
145        return has_api(type_name)
@classmethod
def show_all(cls) -> List:
131    @classmethod
132    def show_all(cls) -> List:
133        """Show all POSSIBLE API types of a given class"""
134        return [x for x, y in cls.__members__.items()]

Show all POSSIBLE API types of a given class

@classmethod
def show_available(cls) -> bool:
136    @classmethod
137    def show_available(cls) -> bool:
138        """Show all AVAILABLE API types of a given class"""
139        return [library.value[1] for library in list(cls) if library.value[0] is True]

Show all AVAILABLE API types of a given class

@classmethod
def check_type(cls, type_name: str) -> bool:
141    @classmethod
142    def check_type(cls, type_name: str) -> bool:
143        """Check for a SINGLE API availability"""
144        type_name = type_name.upper()
145        return has_api(type_name)

Check for a SINGLE API availability

class CueType(BaseEnum):
148class CueType(BaseEnum):
149    f"""Model Provider constants\n
150    Caches and servers\n
151    <NAME: (Availability, IMPORT_NAME)>{base_enum_docstring}
152    {base_enum_docstring}"""
153
154    # Dfferentiation of boolean conditions
155    # GIVEN : The state of all provider modules & servers are marked at launch
156
157    HUB: tuple = (has_api("HUB"), "HUB")
158    KAGGLE: tuple = (has_api("KAGGLE"), "KAGGLE")
159    LLAMAFILE: tuple = (has_api("LLAMAFILE"), "LLAMAFILE")
160    LM_STUDIO: tuple = (has_api("LM_STUDIO"), "LM_STUDIO")
161    MLX_AUDIO: tuple = (has_api("MLX_AUDIO"), "MLX_AUDIO")
162    OLLAMA: tuple = (has_api("OLLAMA"), "OLLAMA")
163    VLLM: tuple = (has_api("VLLM"), "VLLM")
HUB: tuple = <CueType.HUB: (True, 'HUB')>
KAGGLE: tuple = <CueType.KAGGLE: (False, 'KAGGLE')>
LLAMAFILE: tuple = <CueType.LLAMAFILE: (False, 'LLAMAFILE')>
LM_STUDIO: tuple = <CueType.LM_STUDIO: (False, 'LM_STUDIO')>
MLX_AUDIO: tuple = <CueType.MLX_AUDIO: (True, 'MLX_AUDIO')>
OLLAMA: tuple = <CueType.OLLAMA: (True, 'OLLAMA')>
VLLM: tuple = <CueType.VLLM: (False, 'VLLM')>
example_str = ('function_name', 'import.function_name')
class PkgType(BaseEnum):
169class PkgType(BaseEnum):
170    """Package dependency constants
171    Collected info from hub model tags and dependencies
172    <NAME: (Availability, IMPORT_NAME, [Github repositories*]
173    *if applicable, otherwise IMPORT_NAME is pip package
174    NOTE: NAME is colloquial and does not always match IMPORT_NAME>"""
175
176    AUDIOGEN: tuple = (has_api("AUDIOCRAFT"), "AUDIOCRAFT", ["exdysa/facebookresearch-audiocraft-revamp"])  # this fork supports mps
177    BAGEL: tuple = (has_api("BAGEL"), "BAGEL", ["bytedance-seed/BAGEL"])
178    BITNET: tuple = (has_api("BITNET"), "BITNET", ["microsoft/BitNet"])
179    BITSANDBYTES: tuple = (has_api("BITSANDBYTES"), "BITSANDBYTES", [])  # bitsandbytes-foundation/bitsandbytes
180    DFLOAT11: tuple = (has_api("DFLOAT11"), "DFLOAT11", ["LeanModels/DFloat11"])
181    DIFFUSERS: tuple = (has_api("DIFFUSERS"), "DIFFUSERS", [])
182    EXLLAMAV2: tuple = (has_api("EXLLAMAV2"), "EXLLAMAV2", [])  # turboderp-org/exllamav2
183    F_LITE: tuple = (has_api("F_LITE"), "F_LITE", ["fal-ai/f-lite"])
184    HIDIFFUSION: tuple = (has_api("HIDIFFUSION"), "HIDIFFUSION", ["megvii-research/HiDiffusion"])
185    IMAGE_GEN_AUX: tuple = (has_api("IMAGE_GEN_AUX"), "IMAGE_GEN_AUX", ["huggingface/image_gen_aux"])
186    JAX: tuple = (has_api("JAX"), "JAX", [])
187    KERAS: tuple = (has_api("KERAS"), "KERAS", [])
188    LLAMA: tuple = (has_api("LLAMA_CPP"), "LLAMA_CPP", [])
189    LUMINA_MGPT: tuple = (has_api("INFERENCE_SOLVER"), "INFERENCE_SOLVER", ["Alpha-VLLM/Lumina-mGPT"])
190    LUMINA_MGPT2: tuple = (has_api("INFERENCE_SOLVER"), "INFERENCE_SOLVER", ["Alpha-VLLM/Lumina-mGPT-2.0"])
191    MFLUX: tuple = (has_api("MFLUX"), "MFLUX", [])  # "filipstrand/mflux"
192    MLX_AUDIO: tuple = (CueType.check_type("MLX_AUDIO"), "MLX_AUDIO", [])  # Blaizzy/mlx-audio
193    MLX_CHROMA: tuple = (has_api("CHROMA"), "CHROMA", ["exdysa/jack813-mlx-chroma"])
194    MLX_LM: tuple = (has_api("MLX_LM"), "MLX_LM", [])  # "ml-explore/mlx-lm"
195    MLX_VLM: tuple = (has_api("MLX_VLM"), "MLX_VLM", [])  # Blaizzy/mlx-vlm
196    MLX: tuple = (has_api("MLX_LM"), "MLX", [])
197    ONNX: tuple = (has_api("ONNX"), "ONNX", ["ONNX"])
198    ORPHEUS_TTS: tuple = (has_api("ORPHEUS_TTS"), "ORPHEUS_TTS", ["canopyai/Orpheus-TTS"])
199    OUTETTS: tuple = (has_api("OUTETTS"), "OUTETTS", ["edwko/OuteTTS"])
200    PARLER_TTS: tuple = (has_api("PARLER_TTS"), "PARLER_TTS", ["huggingface/parler-tts"])
201    PLEIAS: tuple = (has_api("PLEIAS"), "PLEIAS", ["exdysa/Pleias-Pleias-RAG-Library"])  # bypasses vllm for macos to avoid requiring gcc/AVIX
202    SENTENCE_TRANSFORMERS: tuple = (has_api("SENTENCE_TRANSFORMERS"), "SENTENCE_TRANSFORMERS", [])  # UKPLab/sentence-transformers
203    SHOW_O: tuple = (has_api("SHOW_O"), "SHOW_O", ["showlab/show-o"])
204    SPANDREL_EXTRA_ARCHES: tuple = (has_api("SPANDREL_EXTRA_ARCHES"), "SPANDREL_EXTRA_ARCHES", [])
205    SPANDREL: tuple = (has_api("SPANDREL"), "SPANDREL", [])
206    SVDQUANT: tuple = (has_api("NUNCHAKU"), "NUNCHAKU", ["mit-han-lab/nunchaku"])
207    TENSORFLOW: tuple = (has_api("TENSORFLOW"), "TENSORFLOW", [])
208    TORCH: tuple = (has_api("TORCH"), "TORCH", [])  # Possible that torch is NOT needed (mlx_lm, or some other unforeseen future )
209    TORCHAUDIO: tuple = (has_api("TORCHAUDIO"), "TORCHAUDIO", [])
210    TORCHVISION: tuple = (has_api("TORCHVISION"), "TORCHVISION", [])
211    TRANSFORMERS: tuple = (has_api("TRANSFORMERS"), "TRANSFORMERS", [])
212    VLLM: tuple = (CueType.check_type("VLLM"), "VLLM", [])

Package dependency constants Collected info from hub model tags and dependencies

AUDIOGEN: tuple = <PkgType.AUDIOGEN: (False, 'AUDIOCRAFT', ['exdysa/facebookresearch-audiocraft-revamp'])>
BAGEL: tuple = <PkgType.BAGEL: (False, 'BAGEL', ['bytedance-seed/BAGEL'])>
BITNET: tuple = <PkgType.BITNET: (False, 'BITNET', ['microsoft/BitNet'])>
BITSANDBYTES: tuple = <PkgType.BITSANDBYTES: (False, 'BITSANDBYTES', [])>
DFLOAT11: tuple = <PkgType.DFLOAT11: (False, 'DFLOAT11', ['LeanModels/DFloat11'])>
DIFFUSERS: tuple = <PkgType.DIFFUSERS: (True, 'DIFFUSERS', [])>
EXLLAMAV2: tuple = <PkgType.EXLLAMAV2: (False, 'EXLLAMAV2', [])>
F_LITE: tuple = <PkgType.F_LITE: (False, 'F_LITE', ['fal-ai/f-lite'])>
HIDIFFUSION: tuple = <PkgType.HIDIFFUSION: (False, 'HIDIFFUSION', ['megvii-research/HiDiffusion'])>
IMAGE_GEN_AUX: tuple = <PkgType.IMAGE_GEN_AUX: (False, 'IMAGE_GEN_AUX', ['huggingface/image_gen_aux'])>
JAX: tuple = <PkgType.JAX: (True, 'JAX', [])>
KERAS: tuple = <PkgType.KERAS: (False, 'KERAS', [])>
LLAMA: tuple = <PkgType.LLAMA: (True, 'LLAMA_CPP', [])>
LUMINA_MGPT: tuple = <PkgType.LUMINA_MGPT: (False, 'INFERENCE_SOLVER', ['Alpha-VLLM/Lumina-mGPT'])>
LUMINA_MGPT2: tuple = <PkgType.LUMINA_MGPT2: (False, 'INFERENCE_SOLVER', ['Alpha-VLLM/Lumina-mGPT-2.0'])>
MFLUX: tuple = <PkgType.MFLUX: (True, 'MFLUX', [])>
MLX_AUDIO: tuple = <PkgType.MLX_AUDIO: (True, 'MLX_AUDIO', [])>
MLX_CHROMA: tuple = <PkgType.MLX_CHROMA: (False, 'CHROMA', ['exdysa/jack813-mlx-chroma'])>
MLX_LM: tuple = <PkgType.MLX_LM: (True, 'MLX_LM', [])>
MLX_VLM: tuple = <PkgType.MLX_VLM: (True, 'MLX_VLM', [])>
MLX: tuple = <PkgType.MLX: (True, 'MLX', [])>
ONNX: tuple = <PkgType.ONNX: (True, 'ONNX', ['ONNX'])>
ORPHEUS_TTS: tuple = <PkgType.ORPHEUS_TTS: (False, 'ORPHEUS_TTS', ['canopyai/Orpheus-TTS'])>
OUTETTS: tuple = <PkgType.OUTETTS: (False, 'OUTETTS', ['edwko/OuteTTS'])>
PARLER_TTS: tuple = <PkgType.PARLER_TTS: (False, 'PARLER_TTS', ['huggingface/parler-tts'])>
PLEIAS: tuple = <PkgType.PLEIAS: (False, 'PLEIAS', ['exdysa/Pleias-Pleias-RAG-Library'])>
SENTENCE_TRANSFORMERS: tuple = <PkgType.SENTENCE_TRANSFORMERS: (False, 'SENTENCE_TRANSFORMERS', [])>
SHOW_O: tuple = <PkgType.SHOW_O: (False, 'SHOW_O', ['showlab/show-o'])>
SPANDREL_EXTRA_ARCHES: tuple = <PkgType.SPANDREL_EXTRA_ARCHES: (False, 'SPANDREL_EXTRA_ARCHES', [])>
SPANDREL: tuple = <PkgType.SPANDREL: (False, 'SPANDREL', [])>
SVDQUANT: tuple = <PkgType.SVDQUANT: (False, 'NUNCHAKU', ['mit-han-lab/nunchaku'])>
TENSORFLOW: tuple = <PkgType.TENSORFLOW: (False, 'TENSORFLOW', [])>
TORCH: tuple = <PkgType.TORCH: (True, 'TORCH', [])>
TORCHAUDIO: tuple = <PkgType.TORCHAUDIO: (True, 'TORCHAUDIO', [])>
TORCHVISION: tuple = <PkgType.TORCHVISION: (True, 'TORCHVISION', [])>
TRANSFORMERS: tuple = <PkgType.TRANSFORMERS: (True, 'TRANSFORMERS', [])>
VLLM: tuple = <PkgType.VLLM: (False, 'VLLM', [])>
class ChipType(enum.Enum):
215class ChipType(Enum):
216    f"""Device constants\n
217    CUDA, MPS, XPU, MTIA [Supported PkgTypes]\n
218    {base_enum_docstring}"""
219
220    def __call__(cls):
221        cls.initialie_device()
222
223    @classmethod
224    def initialize_device(cls) -> None:
225        chip_types = [
226            (
227                "CUDA",
228                [
229                    PkgType.BAGEL,
230                    PkgType.BITSANDBYTES,
231                    PkgType.DFLOAT11,
232                    PkgType.EXLLAMAV2,
233                    PkgType.F_LITE,
234                    PkgType.LUMINA_MGPT,
235                    PkgType.ORPHEUS_TTS,
236                    PkgType.OUTETTS,
237                    PkgType.VLLM,
238                ],
239            ),
240            ("MPS", [PkgType.MFLUX, PkgType.MLX_AUDIO, PkgType.MLX_LM, PkgType.BAGEL]),
241            ("XPU", []),
242            ("MTIA", []),
243        ]
244        cls._device = first_available(assign=True, init=True, clean=True)  # pylint:disable=no-member, protected-access
245        if hasattr(cls._device, "type"):
246            gpu = cls._device.type
247        else:
248            gpu = ""
249        for name, pkg_type in chip_types:
250            setattr(cls, name, (name.lower() in gpu, name, pkg_type))
251        setattr(
252            cls,
253            "CPU",
254            (
255                True,
256                "CPU",
257                [
258                    PkgType.AUDIOGEN,
259                    PkgType.PARLER_TTS,
260                    PkgType.LLAMA,
261                    PkgType.HIDIFFUSION,
262                    PkgType.SENTENCE_TRANSFORMERS,
263                    PkgType.DIFFUSERS,
264                    PkgType.TRANSFORMERS,
265                    PkgType.TORCH,
266                ],
267            ),
268        )
269
270    @classmethod
271    def _show_all(cls) -> List[str]:
272        """Show all POSSIBLE processor types"""
273        atypes = [atype for atype in cls.__dict__ if "_" not in atype]
274        return atypes
275
276    @classmethod
277    def _show_ready(cls, api_name: Optional[str] = None) -> Union[List[str], bool]:
278        """Show all READY devices.\n
279        If api_name is provided, checks if the specific API is ready.
280        :param api_name: Boolean check for the specific API by name, defaults to None
281        :return: `bool` or list of ready devices
282        """
283        atypes = cls._show_all()
284        if api_name:
285            return api_name.upper() in [x for x in atypes if getattr(cls, x)[0]]
286        return [getattr(cls, x) for x in atypes if getattr(cls, x)[0] is True]
287
288    @classmethod
289    def _show_pkgs(cls) -> Union[List[PkgType], str]:
290        """Return compatible PkgTypes for all available chipsets\n
291        If no chipsets are detected, returns onlyCPU compatibility options\n
292        :return: `PkgType`s for the available processors including CPU
293        """
294        pkg_names = getattr(cls, "CPU")[-1]
295        atypes = cls._show_ready()
296        available = [pkg[1] for pkg in atypes if pkg[0] is True]
297        priority = next(iter(available), "CPU") if available else "CPU"
298        if priority not in [pkg[1] for pkg in cls._show_all() if not pkg[2]] and priority != "CPU":
299            pkg_names = atypes[0][2] + pkg_names
300        return pkg_names
@classmethod
def initialize_device(cls) -> None:
223    @classmethod
224    def initialize_device(cls) -> None:
225        chip_types = [
226            (
227                "CUDA",
228                [
229                    PkgType.BAGEL,
230                    PkgType.BITSANDBYTES,
231                    PkgType.DFLOAT11,
232                    PkgType.EXLLAMAV2,
233                    PkgType.F_LITE,
234                    PkgType.LUMINA_MGPT,
235                    PkgType.ORPHEUS_TTS,
236                    PkgType.OUTETTS,
237                    PkgType.VLLM,
238                ],
239            ),
240            ("MPS", [PkgType.MFLUX, PkgType.MLX_AUDIO, PkgType.MLX_LM, PkgType.BAGEL]),
241            ("XPU", []),
242            ("MTIA", []),
243        ]
244        cls._device = first_available(assign=True, init=True, clean=True)  # pylint:disable=no-member, protected-access
245        if hasattr(cls._device, "type"):
246            gpu = cls._device.type
247        else:
248            gpu = ""
249        for name, pkg_type in chip_types:
250            setattr(cls, name, (name.lower() in gpu, name, pkg_type))
251        setattr(
252            cls,
253            "CPU",
254            (
255                True,
256                "CPU",
257                [
258                    PkgType.AUDIOGEN,
259                    PkgType.PARLER_TTS,
260                    PkgType.LLAMA,
261                    PkgType.HIDIFFUSION,
262                    PkgType.SENTENCE_TRANSFORMERS,
263                    PkgType.DIFFUSERS,
264                    PkgType.TRANSFORMERS,
265                    PkgType.TORCH,
266                ],
267            ),
268        )
CUDA = (False, 'CUDA', [<PkgType.BAGEL: (False, 'BAGEL', ['bytedance-seed/BAGEL'])>, <PkgType.BITSANDBYTES: (False, 'BITSANDBYTES', [])>, <PkgType.DFLOAT11: (False, 'DFLOAT11', ['LeanModels/DFloat11'])>, <PkgType.EXLLAMAV2: (False, 'EXLLAMAV2', [])>, <PkgType.F_LITE: (False, 'F_LITE', ['fal-ai/f-lite'])>, <PkgType.LUMINA_MGPT: (False, 'INFERENCE_SOLVER', ['Alpha-VLLM/Lumina-mGPT'])>, <PkgType.ORPHEUS_TTS: (False, 'ORPHEUS_TTS', ['canopyai/Orpheus-TTS'])>, <PkgType.OUTETTS: (False, 'OUTETTS', ['edwko/OuteTTS'])>, <PkgType.VLLM: (False, 'VLLM', [])>])
MPS = (True, 'MPS', [<PkgType.MFLUX: (True, 'MFLUX', [])>, <PkgType.MLX_AUDIO: (True, 'MLX_AUDIO', [])>, <PkgType.MLX_LM: (True, 'MLX_LM', [])>, <PkgType.BAGEL: (False, 'BAGEL', ['bytedance-seed/BAGEL'])>])
XPU = (False, 'XPU', [])
MTIA = (False, 'MTIA', [])
CPU = (True, 'CPU', [<PkgType.AUDIOGEN: (False, 'AUDIOCRAFT', ['exdysa/facebookresearch-audiocraft-revamp'])>, <PkgType.PARLER_TTS: (False, 'PARLER_TTS', ['huggingface/parler-tts'])>, <PkgType.LLAMA: (True, 'LLAMA_CPP', [])>, <PkgType.HIDIFFUSION: (False, 'HIDIFFUSION', ['megvii-research/HiDiffusion'])>, <PkgType.SENTENCE_TRANSFORMERS: (False, 'SENTENCE_TRANSFORMERS', [])>, <PkgType.DIFFUSERS: (True, 'DIFFUSERS', [])>, <PkgType.TRANSFORMERS: (True, 'TRANSFORMERS', [])>, <PkgType.TORCH: (True, 'TORCH', [])>])
class GenTypeC(pydantic.main.BaseModel):
312class GenTypeC(BaseModel):
313    """
314    Generative inference types in ***C***-dimensional order\n
315    ***Comprehensiveness***, sorted from 'most involved' to 'least involved'\n
316    The terms define 'artistic' and ambiguous operations\n
317
318    :param clone: Copying identity, voice, exact mirror
319    :param sync: Tone, tempo, color, quality, genre, scale, mood
320    :param translate: A range of comprehensible approximations\n
321    """
322
323    clone: Annotated[Callable | None, Field(default=None)]
324    sync: Annotated[Callable | None, Field(default=None)]
325    translate: Annotated[Callable | None, Field(default=None)]

Generative inference types in C-dimensional order

Comprehensiveness, sorted from 'most involved' to 'least involved'

The terms define 'artistic' and ambiguous operations

Parameters
  • clone: Copying identity, voice, exact mirror
  • sync: Tone, tempo, color, quality, genre, scale, mood
  • translate: A range of comprehensible approximations
clone: Annotated[Optional[Callable], FieldInfo(annotation=NoneType, required=False, default=None)] = None
sync: Annotated[Optional[Callable], FieldInfo(annotation=NoneType, required=False, default=None)] = None
translate: Annotated[Optional[Callable], FieldInfo(annotation=NoneType, required=False, default=None)] = None
class GenTypeCText(pydantic.main.BaseModel):
328class GenTypeCText(BaseModel):
329    """
330    Generative inference types in ***C***-dimensional order for text operations\n
331    ***Comprehensiveness***, sorted from 'most involved' to 'least involved'\n
332    The terms define 'concrete' and more rigid operations\n
333
334    :param research: Quoting, paraphrasing, and deriving from sources
335    :param chain_of_thought: A performance of processing step-by-step (similar to `reasoning`)
336    :param question_answer: Basic, straightforward responses\n
337    """
338
339    research: Annotated[Optional[Callable | None], Field(default=None, examples=example_str)]
340    chain_of_thought: Annotated[Optional[Callable | None], Field(default=None, examples=example_str)]
341    question_answer: Annotated[Optional[Callable | None], Field(default=None, examples=example_str)]

Generative inference types in C-dimensional order for text operations

Comprehensiveness, sorted from 'most involved' to 'least involved'

The terms define 'concrete' and more rigid operations

Parameters
  • research: Quoting, paraphrasing, and deriving from sources
  • chain_of_thought: A performance of processing step-by-step (similar to reasoning)
  • question_answer: Basic, straightforward responses
research: Annotated[Optional[Callable], FieldInfo(annotation=NoneType, required=False, default=None, examples=('function_name', 'import.function_name'))] = None
chain_of_thought: Annotated[Optional[Callable], FieldInfo(annotation=NoneType, required=False, default=None, examples=('function_name', 'import.function_name'))] = None
question_answer: Annotated[Optional[Callable], FieldInfo(annotation=NoneType, required=False, default=None, examples=('function_name', 'import.function_name'))] = None
class GenTypeE(pydantic.main.BaseModel):
344class GenTypeE(BaseModel):
345    """
346    Generative inference operation types in ***E***-dimensional order \n
347    ***Equivalence***, lists sorted from 'highly-similar' to 'loosely correlated.'"\n
348    :param universal: Affecting all conversions
349    :param text: Text-only conversions\n
350
351    ***multimedia generation***
352    ```
353    Y-axis: Detail (Most involved to least involved)
354
355    │                             clone
356    │                 sync
357    │ translate
358
359    +───────────────────────────────────────> X-axis: Equivalence (Loosely correlated to highly similar)
360    ```
361    ***text generation***
362    ```
363    Y-axis: Detail (Most involved to least involved)
364
365    │                           research
366    │             chain-of-thought
367    │ question/answer
368
369    +───────────────────────────────────────> X-axis:  Equivalence (Loosely correlated to highly similar)
370    ```
371
372    This is essentially the translation operation of C types, and the mapping of them to E \n
373
374    An abstract generalization of the set of all multimodal generative synthesis processes\n
375    The sum of each coordinate pair reflects effective compute use\n
376    In this way, both C types and their similarity are translatable, but not 1:1 identical\n
377    Text is allowed to perform all 6 core operations. Other media perform only 3.\n
378    """
379
380    # note: `sync` may have better terms, such as 'harmonize' or 'attune'. `sync` was chosen because it is shorter
381
382    universal: GenTypeC = GenTypeC(clone=None, sync=None, translate=None)
383    text: GenTypeCText = GenTypeCText(research=None, chain_of_thought=None, question_answer=None)

Generative inference operation types in E-dimensional order

Equivalence, lists sorted from 'highly-similar' to 'loosely correlated.'"

Parameters
  • universal: Affecting all conversions
  • text: Text-only conversions

multimedia generation

Y-axis: Detail (Most involved to least involved)
│
│                             clone
│                 sync
│ translate
│
+───────────────────────────────────────> X-axis: Equivalence (Loosely correlated to highly similar)

text generation

Y-axis: Detail (Most involved to least involved)
│
│                           research
│             chain-of-thought
│ question/answer
│
+───────────────────────────────────────> X-axis:  Equivalence (Loosely correlated to highly similar)

This is essentially the translation operation of C types, and the mapping of them to E

An abstract generalization of the set of all multimodal generative synthesis processes

The sum of each coordinate pair reflects effective compute use

In this way, both C types and their similarity are translatable, but not 1:1 identical

Text is allowed to perform all 6 core operations. Other media perform only 3.

universal: GenTypeC = GenTypeC(clone=None, sync=None, translate=None)
text: GenTypeCText = GenTypeCText(research=None, chain_of_thought=None, question_answer=None)
VALID_CONVERSIONS = ['text', 'image', 'music', 'speech', 'audio', 'video', '3d', 'vector_graphic', 'upscale_image']
VALID_JUNCTIONS = ['']
tasks = ['audio-classification', 'automatic-speech-recognition', 'depth-estimation', 'document-question-answering', 'feature-extraction', 'fill-mask', 'image-classification', 'image-feature-extraction', 'image-segmentation', 'image-text-to-text', 'image-to-image', 'image-to-text', 'mask-generation', 'ner', 'object-detection', 'question-answering', 'sentiment-analysis', 'summarization', 'table-question-answering', 'text-classification', 'text-generation', 'text-to-audio', 'text-to-speech', 'text2text-generation', 'token-classification', 'translation', 'video-classification', 'visual-question-answering', 'vqa', 'zero-shot-audio-classification', 'zero-shot-classification', 'zero-shot-image-classification', 'zero-shot-object-detection', 'translation_XX_to_YY']
VALID_TASKS = {<CueType.VLLM: (False, 'VLLM')>: {('text', 'text'): ['text'], ('image', 'text'): ['vision']}, <CueType.OLLAMA: (True, 'OLLAMA')>: {('text', 'text'): ['mllama'], ('image', 'text'): ['llava', 'vllm']}, <CueType.LLAMAFILE: (False, 'LLAMAFILE')>: {('text', 'text'): ['text']}, <CueType.LM_STUDIO: (False, 'LM_STUDIO')>: {('text', 'text'): ['llm']}, <CueType.HUB: (True, 'HUB')>: {('image', 'image'): ['image-to-image', 'inpaint', 'inpainting', 'depth-to-image', 'i2i', 'image-to-image', 'any-to-any'], ('text', 'image'): ['kolors', 'kolorspipeline', 'image-generation', 'any-to-any', 'text-to-image', 'chromapipeline'], ('image', 'text'): ['image-classification', 'image-to-text', 'image-text-to-text', 'visual-question-answering', 'image-captioning', 'image-segmentation', 'depth-estimation', 'image-feature-extraction', 'mask-generation', 'object-detection', 'visual-question-answering', 'keypoint-detection', 'vllm', 'vqa', 'vision', 'zero-shot-object-detection', 'zero-shot-image-classification', 'timm', 'zero-shot image classification', 'any-to-any', 'vidore'], ('image', 'video'): ['image-to-video', 'i2v', 'reference-to-video', 'refernce-to-video'], ('video', 'text'): ['video-classification'], ('text', 'video'): ['video generation', 't2v', 'text-to-video', 'HunyuanVideoPipeline'], ('text', 'text'): ['any-to-any', 'named entity recognition', 'entity typing', 'relation classification', 'question answering', 'fill-mask', 'chat', 'conversational', 'text-generation', 'causal-lm', 'text2text-generation', 'document-question-answering', 'feature-extraction', 'question-answering', 'sentiment-analysis', 'summarization', 'table-question-answering', 'text-classification', 'token-classification', 'translation', 'zero-shot-classification', 'translation_xx_to_yy', 't2t', 'chatglm', 'exbert'], ('text', 'audio'): ['text-to-audio', 't2a', 'any-to-any', 'text-to-audio', ' musicldmpipeline', 'musicgen', 'audiocraft', 'audiogen', 'AudioLDMPipeline', 'AudioLDM2Pipeline'], ('audio', 'text'): ['zero-shot-audio-classification', 'audio-classification', 'a2t', 'audio-text-to-text', 'any-to-any'], ('text', 'speech'): ['text-to-speech', 'tts', 'any-to-any', 'annotation'], ('speech', 'text'): ['speech-to-text', 'speech', 'speech-translation', 'speech-summarization', 'automatic-speech-recognition', 'dictation', 'stt', 'any-to-any', 'hf-asr-leaderboard']}, <CueType.KAGGLE: (False, 'KAGGLE')>: {('text', 'text'): ['text']}}