Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YAML Parser #3

Open
wants to merge 2 commits into
base: xsn/model_merge
Choose a base branch
from
Open

Conversation

dnhkng
Copy link

@dnhkng dnhkng commented Mar 9, 2024

This adds a YAML parser to make is pretty easy to write high-level model merging configs.

It should be used so:
python yamlconfig.py some.yml
It operates on yaml files with this structure:

slices:
- sources:
  - layer_range: [0, 1]
    model: models/mistral-7b-instruct-v0.1.Q5_K_M.gguf
    weight: 0.6
  - layer_range: [0, 1]
    model: models/zephyr-7b-beta.Q5_K_M.gguf
    weight: 0.4
  merge_method: slerp
- sources:
  - layer_range: [1, 16]
    model: models/mistral-7b-instruct-v0.1.Q5_K_M.gguf
    weight: 0.2
  - layer_range: [3, 18]
    model: models/zephyr-7b-beta.Q5_K_M.gguf
    weight: 0.8
  merge_method: linear
- sources:
  - layer_range: [8, 24]
    model: models/mistral-7b-instruct-v0.1.Q5_K_M.gguf
  merge_method: copy
- sources:
  - layer_range: [16, 30]
    model: models/zephyr-7b-beta.Q5_K_M.gguf
  merge_method: copy
- sources:
  - layer_range: [31, 32]
    model: models/mistral-7b-instruct-v0.1.Q5_K_M.gguf
    weight: 0.1
  - layer_range: [31, 32]
    model: models/zephyr-7b-beta.Q5_K_M.gguf
    weight: 0.9
  merge_method: linear

This config does all kinds of model merging by slices. Slices can be copied from various source models, or combined in various ways in various orders. There is also a simpler 'model' based merging system, where similar models can be merged by just linear or spherical interpolation.

Note, the current low-level method for this code:

- sources:
  - layer_range: [31, 32]
    model: models/mistral-7b-instruct-v0.1.Q5_K_M.gguf
    weight: 0.1
  - layer_range: [31, 32]
    model: models/zephyr-7b-beta.Q5_K_M.gguf
    weight: 0.9

would be:

output layer 46
all linear 31,31,0.1,0.9

Currently, the model identity is not needed, and so the format is:
layer, layer, weight, weight

However, if we were working with more than 2 models, or the order changed, this would confuse us. e.g. we want to try merging 3 models, and sometimes were are merging [1,2], and other times [2,3], or we might have the order reversed [2,1].
Perhaps we should use the format:
model, model, layer, layer, weigh, weight

If this format seems better, I will update the parser to match.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant