Repository navigation
epic: SQLite database implementation #1241
Description
Implement a ModelListUtils class base on this discussion #1154
Overview
The ModelListUtils class provides a robust and thread-safe interface for managing a list of machine learning models. It handles operations such as adding, updating, deleting, and retrieving model information, with a focus on maintaining unique identifiers for each model.
Key Features
- Thread-safe Operations: Uses mutex locking to ensure thread safety for all operations.
- File-based Storage: Manages model information in a text file, allowing for persistence between program runs.
- Unique Identifier Generation: Automatically generates unique, shortened aliases for models.
- CRUD Operations: Supports Creating, Reading, Updating, and Deleting model entries.
- Error Handling: Robust error checking and exception throwing for invalid operations.
Main Components
ModelEntry Struct
Represents a single model entry with fields:
model_id: Unique identifier for the modelauthor_repo_id: Author or repository identifierbranch_name: Branch name in the repositorypath_to_model_yaml: Path to the model's YAML filemodel_alias: Shortened alias for the modelstatus: Current status of the model (READY or RUNNING)
ModelListUtils Class Methods
-
LoadModelList()
- Loads model entries from the file, creating the file if it doesn't exist.
- Returns a vector of ModelEntry objects.
-
SaveModelList()
- Saves the current list of model entries to the file.
-
GetModelInfo(identifier)
- Retrieves model information based on model_id or model_alias.
- Throws an exception if the model is not found.
-
AddModelEntry(new_entry, use_short_alias)
- Adds a new model entry to the list.
- Optionally generates a shortened alias for the model.
- Ensures uniqueness of model_id and model_alias.
-
UpdateModelEntry(identifier, updated_entry)
- Updates an existing model entry.
- Identified by either model_id or model_alias.
-
DeleteModelEntry(identifier)
- Deletes a model entry if it exists and is in READY state.
-
PrintModelInfo(entry)
- Prints detailed information about a model entry.
-
GenerateShortenedAlias(model_id, entries)
- Generates a unique, shortened alias for a model.
- Uses a hierarchical approach to create aliases, prioritizing brevity while ensuring uniqueness.
Alias Generation Logic
The GenerateShortenedAlias function creates aliases in the following order:
- Filename only (e.g.,
model_id_xxx) - Parent directory + filename (e.g.,
llama3.1-7b-gguf:model_id_xxx) - Grandparent directory + parent directory + filename (e.g.,
bartowski:llama3.1-7b-gguf/model_id_xxx) - Full path (e.g.,
huggingface.co:bartowski/llama3.1-7b-gguf/model_id_xxx)
It returns the shortest unique alias, appending a numeric suffix if necessary to ensure uniqueness.
Metadata
Metadata
Labels
Type
Projects
- StatusShow more project fieldsCompleted
Activity
freelerobot commentedon Sep 23, 2024
Problem
Success Criteria
models.listdoes not duplicate information inmodel.yamllistandyamlintroduces edge cases & unmaintainabilitycortex pull/runcorrectly updates models.listcortex importcorrectly updates models.listRelated
Questions
models.listormodel.list? The former is more grammatically correct.author_repo_id,branch_nameacross both model.yaml and models.list? Should we move fields frommodel.yamlintolistinstead? OR vice versa?statusthan to do file IO during runtime?models.list? i.e. if we change the schema in the future, it is trackable.llama3 local importedseems redundantllama3 local imported /Users/nicolezhu/cortexcpp-nightly/models/imported/llama3.yml llama3 READYTldr
At the moment, the current models.list design is complicated. I am worried ab out the long term maintainability and edge cases.
My 2cents:
id,alias,yaml path, maybebinary pathsource url,model name, all hyperparams...cc @dan-homebrew
freelerobot commentedon Sep 23, 2024
cc @louis-jan to take a look and lets discuss here 🙏
[-]model.list implementation[/-][+]epic: model.list implementation[/+]nguyenhoangthuan99 commentedon Sep 23, 2024
models.list.author_repo_id, branch_nametomodels.listmodels.list, I'll find the proper way to implement it.llama3 local imported /Users/nicolezhu/cortexcpp-nightly/models/imported/llama3.yml llama3 READYbecause we are organizingmodels.listas a text file, so for easier to implement and avoid unexpected bugs, we must ensure the number of element in a line is constant.for example:
This is our final model folder structure from this discussion #1154
So we are aiming to make
models.listcan support model from many sources (local imported, cortexso, other hugging face branch, nvidia-ngc, ... ).author_repo_id, branch_namealso help us to know the source of model. We can use this information to show when list models.6. I also think database for
models.listinstead of text file is necessary7. Currently,
models.listis first created as the first command cannot findmodels.listfile. The issue #1285 caused by model pull command, still at old version and hasn't supportedmodels.listyet. James and Sang is working with model run and model pull command with newmodels.list.freelerobot commentedon Sep 23, 2024
Gotcha, much of the above makes sense:
models.listin installation, as we write the cortexcpp folder? What do we get from dynamically creating it later on?nguyenhoangthuan99 commentedon Sep 23, 2024
model.list: This is a header/metadata index containing information to identify models.model.yml: This is a configuration file that includes information for loading and running models. In the future, it may also be used for features like recommending inference parameters(ngl, context length) based on model specifications.author_repo_idandbranch_name: These are not used for inference purposes. They are sometimes included in thenameandmodelfields, butnameandmodelprimary purpose is to help the LlamaCpp engine distinguish between different models.enginesandmodelsfolders are created automatically when they're not found at the first run.models.listfile to prevent crashes when running test cases in the Continuous Integration (CI) environment.freelerobot commentedon Sep 23, 2024
dan-menlo commentedon Sep 24, 2024
@0xSage @nguyenhoangthuan99 @louis-jan: If we are eventually going to move to a simple SQLite database for model management, I would prefer to do it now:
SQLite vs. models.list
models.list, and a file corruption would brick both Jan and Cortexmodels.listfields are clearly structured, and SQL is better for this caseVersioning & Migration
cc @vansangpfiev @namchuai
dan-menlo commentedon Sep 24, 2024
@nguyenhoangthuan99 @vansangpfiev @louis-jan @namchuai Let's start dealing with Model List as a SQLite database, and thinking through clearly what we need for Cortex to function.
I also see SQLite database would also allow us to track things like
status, which is useful for operations.model_id: Unique identifier for the modelauthor_repo_id: Author or repository identifierbranch_name: Branch name in the repositorypath_to_model_yaml: Path to the model's YAML filemodel_alias: Shortened alias for the modelstatus: Current status of the model (READY or RUNNING)However, I note in our discussion, the example seems to have a
local,importedin the struct.As part of this discussion exercise, can we do a few mockup entries, to see whether our assumptions work?
openhermes2.5:7b)namchuai commentedon Sep 24, 2024
IMO, I'm happy with using database approach. File-based approach does not play well with migration.
Couple of thoughts:
cortex update(maybe even downgrade) might need to update database schema as well?vansangpfiev commentedon Sep 24, 2024
I agree with the database approach. @nguyenhoangthuan99 implemented a good interface for model.list, so only need to change the implementation to replace it with database.
[-]epic: model.list implementation[/-][+]epic: SQLite database implementation[/+]gabbyong commentedon Oct 3, 2024
Closing as complete - sqlite
