Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

epic: Implement new Model Folder and model.yaml #1154

Closed

Description

@dan-menlo

Goal

  • We should have a model folder that is able to handle different models
    • Built-in models (e.g. janhq/llama3:7b-tensorrt-llm)
    • Huggingface GGUF repos with multiple quants (e.g. bartowski/llama3-gguf)
    • Huggingface specific GGUF (may have multiple from same directory)
    • In future: Nvidia NGC or TensorRT Cloud
  • Do we use sub-folders?
  • How does model.yaml work?
  • Model detection should not depend on model folder

Tasklist

Decisions

Bugs

Edge Cases

Activity

  1. converted this from a draft issue on Sep 8, 2024
  2. added
    type: epic
    on Sep 8, 2024
  3. changed the title [-]epic: Model Folder finalize structure[/-] [+]epic: Finalize how Model Folder and model.yaml works[/+] on Sep 8, 2024
  4. moved this to Scheduled in Menloon Sep 8, 2024
  5. added
    category: model management
    P0: critical
    on Sep 9, 2024
  6. freelerobot commented on Sep 9, 2024

    @freelerobot
    Contributor

    Legacy model folder structure: janhq/jan#3541 (comment)

  7. louis-jan commented on Sep 10, 2024

    @louis-jan

    Model detection should not depend on model folder?

    Model detection depends on the model folder, which would introduce performance issues since:

    • Every time the app loads, it needs to scan through the model folder hierarchy.
    • Costly filesystem watching (Notify the app of changes)

    This means we likely depend on the manifest file, where it is the source of trust, as it links to all available models with different folder structures.

    • This introduces a periodically scanning folder watchdog. A delay problem may occur.
    • Everything just works with references or symlinks.

    Structures do not work well in the past or I have seen around:

    1. Shallow structure

    All of the YAML files are placed in the root of the directory.

    Pros: Fast lookup - just filter out YAML files from the root folder to list models.

    Cons: Easy to duplicate, cannot work with different model families. Same name for different branches/authors/engines.
    Slower over time since n models = 2n items. 2 rm operations to remove a model.

    E.g. llama3 of cortexhub | gguf | Q4 | Q8 | onnx | thebloke

    
    /models
        /[model1]
           /[model1].bin
           /[model1].gguf
        /[model1].yaml | json
    

    2. One level of deep structure

    All files are placed in a model folder.

    Pros: Easy to manage model by model, 1 rm operation can remove the entire model folder.

    Cons: Slow list iteration, the app has to loop through every single folder and check if the model file exists. So many FS operations.

    
    /models
        /[model1]
           /[model].bin
           /[model].gguf
           /[model].yaml | json
    

    Getting our Filesystem hierarchy less wrong with these 3 following Principles:

    Principle 1: The Single-Question Principle
    At each level of the hierarchy, strive to make all folder names answer the same question.

    Principle 2: The Domain Principle
    Organize files in different domains differently.

    Principle 3: The Depth Principle
    Prefer deep hierarchies over shallow ones.

    The structures would be similar to this:

    /models
      ├── manifest.yaml
      ├── /metadatas
      │   ├── llama3.1-7B_Q4_KM.yaml (How to generate a file name that is unique across models?)
      │   └── mistral-7B_Q4_KM.yaml
      └── /sources
          ├── /huggingface
          │   ├── /cortexso
          │   │   ├── /llama3-1
          │   │   │   ├── /gguf
          │   │   │   │   ├── /main
          │   │   │   │   │   └── llama3.1_Q4_KM.gguf
          │   │   │   │   └── /7b
          │   │   │   │       ├── llama3.1_Q4_KM.gguf
          │   │   │   │       └── llama3.1_Q8_KM.gguf
          │   │   │   ├── /onnx
          │   │   │   │   └── /7b
          │   │   │   │       ├── llama3.1.onnx
          │   │   │   │       ├── tokenizer.json
          │   │   │   │       └── gen_config.json
          │   │   │   └── /tensorrt-llm
          │   │   │       └── /7b
          │   │   │           ├── rank0.engine
          │   │   │           ├── tokenizer.model
          │   │   │           └── config.json
          │   │   └── /phi-3
          │   │       └── /onnx
          │   └── /bartowski
          │       └── /Mixtral-8x22B-v0.1
          │           └── /gguf
          │               └── /main
          │                   ├── Mixtral-8x22B-v0.1-IQ3_M-00001-of-00005.gguf
          │                   └── Mixtral-8x22B-v0.1-IQ3_M-00002-of-00005.gguf
          └── /nvidia-ngc
              └── /llama3-1
    

    OR

    /models
      ├── manifest.yaml
      ├── /modelfiles
      │   ├── llama3.1-7B_Q4_KM.yaml
      │   └── mistral-7B_Q4_KM.yaml
      └── /sources
          ├── /huggingface
          │   ├── /cortexso
          │   │   ├── /llama3-1
          │   │   │   ├── /gguf
          │   │   │   │   ├── /main
          │   │   │   │   │   └── llama3.1_Q4_KM.gguf
          │   │   │   │   └── /7b
          │   │   │   │       ├── llama3.1_Q4_KM.gguf
          │   │   │   │       └── llama3.1_Q8_KM.gguf
          │   │   │   ├── /onnx
          │   │   │   │   └── /7b
          │   │   │   │       ├── llama3.1.onnx
          │   │   │   │       ├── tokenizer.json
          │   │   │   │       └── gen_config.json
          │   │   │   └── /tensorrt-llm
          │   │   │       └── /7b
          │   │   │           ├── rank0.engine
          │   │   │           ├── tokenizer.model
          │   │   │           └── config.json
          │   │   └── /phi-3
          │   │       └── /onnx
          │   └── /bartowski
          │       └── /Mixtral-8x22B-v0.1
          │           └── /gguf
          │               └── /main
          │                   ├── Mixtral-8x22B-v0.1-IQ3_M-00001-of-00005.gguf
          │                   └── Mixtral-8x22B-v0.1-IQ3_M-00002-of-00005.gguf
          └── /nvidia-ngc
              └── /llama3-1
    
    1. At each individual level of the sources hierarchy, all options are different responses to the same question: What hub is the source? What repo is in the hub? What model types are supported in the repo? What branch is the model pulled from? What model and what quantization are pulled?
    2. model.yaml files are flattened for quick search in the metadatas so users can easily find the one they want to edit, which boosts the performance of model listing. The filename is a normalized form of model_id.
    3. From the sources folder hierarchy, we can determine the author andformat | engine, so we can get rid of model.yaml's redundant fields. The 'engine' should not be in model.yaml since it's not related to the model (application level) and cannot be reused across applications.
    4. Files are organized differently in different domains (metadatas / sources).
    5. Everything is a symlink, from [model].yaml, we can retrieve the source hierarchies.
    6. Manifest is for caching (optional), which can improve UX and boost performance. This allows us to avoid including all computed fields (such as decorations, sorting order - drag and drop later, or sorting results) in model.yaml (e.g., size, quantization). These fields are not essential when constructing or modifying model.yaml, but they do increase the risk of errors. Since they can be retrieved from the source files, we only need to cache them when populating the model.
    7. Unified model's URL - Determine whether the model is downloaded or not, the local URL and remote URL are quite messy (before file:// and https://). With that model folder hierarchy we can just use 1 universal URL for both. E.g. models://huggingface/bartowski/Mixtral-8x22B-v0.1/main/Mixtral-8x22B-v0.1-IQ3_M-00001-of-00005.gguf.

    ALTERNATIVE PATH:
    Inspired by /etc/apt/sources.list

    I'm still thinking about another path that could address a couple of problems that arise from the structure above where:

    • model.yaml file name can be duplicated
    • An unique model id should be autogenerated somehow. If generate using folder path, it should be where model.yaml is located not the source file. So model.yaml could not be flattened. (might be there is another option that can generate a human readable model name).
    • Less complex structure

    Inspired by the PPA repositories list mechanism. This approach simply put all of the model files in a sources.list. So app can list all of the nested model.yaml without worrying about the performance issue. Also can use any editor to Ctrl + Click to open model.yaml file. (previously I find it hard to look up a model.yaml in a nested model folder)

    But there is also a con where users could not search or view a model folder file without opening the sources.list using an external editor.

    /models
      ├── sources.list (aka models list: models.list)
      └── /sources
          ├── /huggingface
          │   ├── /cortexso
          │   │   ├── /llama3-1
          │   │   │   ├── /gguf
          │   │   │   │   ├── /main
          │   │   │   │   │   ├── llama3.1_Q4_KM.yaml
          │   │   │   │   │   └── llama3.1_Q4_KM.gguf
          │   │   │   │   └── /7b
          │   │   │   │       ├── llama3.1_Q4_KM.yaml
          │   │   │   │       ├── llama3.1_Q4_KM.gguf
          │   │   │   │       ├── llama3.1_Q8_KM.yaml
          │   │   │   │       └── llama3.1_Q8_KM.gguf
          │   │   │   ├── /onnx
          │   │   │   │   └── /7b
          │   │   │   │       ├── llama3.1.yaml
          │   │   │   │       ├── llama3.1.onnx
          │   │   │   │       ├── tokenizer.json
          │   │   │   │       └── gen_config.json
          │   │   │   └── /tensorrt-llm
          │   │   │       └── /7b
          │   │   │           ├── llama3.1.yaml
          │   │   │           ├── rank0.engine
          │   │   │           ├── tokenizer.model
          │   │   │           └── config.json
          │   │   └── /phi-3
          │   │       └── /onnx
          │   └── /bartowski
          │       └── /Mixtral-8x22B-v0.1
          │           └── /gguf
          │               └── /main
          │                   ├── Mixtral-8x22B-v0.1-IQ3_M.yaml
          │                   ├── Mixtral-8x22B-v0.1-IQ3_M-00001-of-00005.gguf
          │                   └── Mixtral-8x22B-v0.1-IQ3_M-00002-of-00005.gguf
          └── /nvidia-ngc
              └── /llama3-1
    

    Design model.yaml structure

    To me, a clean and functioning focused model.yaml file should follow these principles:

    1. Build for Functionality, Not Decoration
    The model.yaml file is built to define core functionalities of the app rather than superficial decorations.

    Its primary role is to allow users to configure advanced model and inference settings, giving them the ability to control and fine-tune how the app interacts with the model. For instance, in cases where legacy models lack certain parameters metadata, maintainers or users can easily edit and update the configuration.

    2. Model Configuration, Not App Caching or Storage
    The file serves as a configuration file for controlling requests and managing model behaviors.

    It is not intended for managing app caching, storage, or persistence layers. All fields must be relevant to controlling the model’s interaction and performance.

    3. Unified Structure for Public Sharing and Best Practices
    The model.yaml follows a unified structure that aims to create a standard practice among authors and developers.

    This structure encourages the publishing and sharing of model configuration settings for various use cases, creating a community-driven trend where the best configurations for different tasks and models are easily accessible.

    The model.yaml would be similar to this

    # BEGIN GENERAL GGUF METADATA
    model: gemma-2-9b-it-Q8_0 # Model ID which is used for request construct - should be unique between models (author / quantization)
    name: Llama 3.1      # metadata.general.name
    version: 1           # metadata.version
    sources:             # can be universal protocol (models://) OR absolute local file path (file://) OR https remote URL (https://)
      - models://huggingface/bartowski/Mixtral-8x22B-v0.1/main/Mixtral-8x22B-v0.1-IQ3_M-00001-of-00005.gguf
      - models://huggingface/bartowski/Mixtral-8x22B-v0.1/main/Mixtral-8x22B-v0.1-IQ3_M-00002-of-00005.gguf
    # END GENERAL GGUF METADATA
    
    # BEGIN INFERENCE PARAMETERS
    # BEGIN REQUIRED
    stop:                # tokenizer.ggml.eos_token_id
      - <|end_of_text|>
      - <|eot_id|>
      - <|eom_id|>
    # END REQUIRED
    # BEGIN OPTIONAL
    stream: true         # Default true?
    top_p: 0.9           # Ranges: 0 to 1
    temperature: 0.6     # Ranges: 0 to 1
    frequency_penalty: 0 # Ranges: 0 to 1
    presence_penalty: 0  # Ranges: 0 to 1
    max_tokens: 8192     # Should be default to context length
    # END OPTIONAL
    # END INFERENCE PARAMETERS
    
    # BEGIN MODEL LOAD PARAMETERS
    # BEGIN REQUIRED
    prompt_template: |+  # tokenizer.chat_template
      <|begin_of_text|><|start_header_id|>system<|end_header_id|>
    
      {system_message}<|eot_id|><|start_header_id|>user<|end_header_id|>
    
      {prompt}<|eot_id|><|start_header_id|>assistant<|end_header_id|>
    # END REQUIRED
    # BEGIN OPTIONAL
    ctx_len: 0          # llama.context_length | 0 or undefined = loaded from model
    ngl: 33             # Undefined = loaded from model
    # END OPTIONAL
    # END MODEL LOAD PARAMETERS

    As described before, other fields like author or engine could be determined by the model folder, or cortex.cpp can detect the model file type.

    We should use the term model since it's consolidated, whereas id is quite server/system specific and not directly related to the LLM model.

    The model value could be generated in case we run local models. It's a DTO property rather than stored property, since it is only used to determine what model (actually from which model is running from what folder path). Overwrite model from model.yaml file is to prevent auto generated mechanism which would work for remote models. E.g. openai/gpt-3.5-turbo.

    Model sources/files is a messy issue, where the program does not know the model is downloaded or not, what is the correct downloaded path, what is the remote path (to redownload). So I really like to use this universal source protocol where:

    models://[hub]/[author]/[repo]/[branch]/[file] which present a remote file URL can be downloaded into the models folder. The logic is to check the file exist following a constructed local file path or download from a constructed remote path built from the universal path.

    cc @dan-homebrew @0xSage

  8. 23 remaining items

  9. moved this from In Progress to Completed in Menloon Sep 24, 2024
  10. moved this from Completed to QA in Menloon Sep 24, 2024
  11. dan-menlo commented on Sep 27, 2024

    @dan-menlo
    ContributorAuthor

    @nguyenhoangthuan99 I am shifting this to @vansangpfiev and tracking Tasklist items, just to keep big picture sitpic of progress.

  12. moved this from QA to In Progress in Menloon Sep 27, 2024
  13. added this to the v1.0.0 milestone on Oct 3, 2024
  14. moved this from Review + QA to Completed in Menloon Oct 3, 2024
  15. moved this from Completed to Review + QA in Menloon Oct 3, 2024
  16. moved this from Review + QA to Completed in Menloon Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P0: criticalcategory: model managementtype: epic

Type

No type

Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions