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

fix: #3558 wrong model metadata import or download from HuggingFace #3725

Merged
merged 2 commits into from
Sep 24, 2024

Conversation

louis-jan
Copy link
Contributor

@louis-jan louis-jan commented Sep 23, 2024

Describe Your Changes

When downloading the HF GGUF model via URL import from the model hub, the model is using default settings instead of the correct settings. The fixed context length is set to 2048, the prompt template is incorrect, and there is an issue with the stop word. However, importing GGUF directly seems to resolve these issues.

Steps to reproduce

Download the HF GGUF model from the model hub using URL import.
Check the settings for context length, prompt template, and stop word.
Compare the settings with the correct settings for the GGUF model.

Expected behavior

The HF GGUF model downloaded via URL import should have the correct settings for context length, prompt template, and stop word, matching the settings when GGUF is imported directly.

Additional context

The issue seems to be specific to downloading the HF GGUF model via URL import from the model hub. Importing GGUF directly does not exhibit the same issue with default settings.

Fixes Issues

Screenshots

Qwen 2.5 download from HF
Screenshot 2024-09-23 at 20 41 21

Code Changes

  1. extensions/model-extension/src/index.test.ts
  2. extensions/model-extension/src/index.ts
  3. extensions/model-extension/src/node/index.ts
  4. extensions/model-extension/src/node/node.test.ts

Here's a summary of the major changes across these files:

index.test.ts

  • Added mock functions for new dependencies (downloadMock, mkdirMock, writeFileSyncMock, copyFileMock).
  • Added setup for a global fetch mock.
  • Imported additional functions for testing (renderJinjaTemplate, Template).
  • Added a new test case for downloadModel with invalid gguf metadata.

index.ts

  • Added support for downloading HF model metadata by fetching and retrieving GGUF metadata.
  • Improved the creation and update of model settings and parameters using fetched metadata.
  • Added a new method retrieveGGUFMetadata that returns a partially updated model based on metadata.
  • Handled conflicts and updated parameters and settings using GGUF metadata.
  • Refactored the eos token handling and merging model configurations.

node/index.ts

  • Removed the original implementation of renderedTemplate from the GGUF metadata parsing process.
  • Added a new function renderJinjaTemplate for parsing Jinja templates based on the metadata.

node/node.test.ts

  • Added tests for the renderJinjaTemplate function.
  • Includes tests handling cases where token IDs are missing or the template is empty.

Detailed Examples

  • GGUF Metadata Handling: Added code to check for and update model settings based on metadata attributes like eos_token_id, context_length, block_count, etc.

    await fs.writeFileSync(modelJsonPath, JSON.stringify(model, null, 2))
    const updatedModel = await this.retrieveGGUFMetadata(metadata)
    model.settings = { ...model.settings, ...updatedModel.settings };
  • Infrastructural Mocks in Tests: Created mocks and their respective test setups to emulate filesystem and network behaviors for more deterministic tests.

    global.fetch = jest.fn(() => Promise.resolve(...));
    expect(sut.downloadModel(...)).rejects.toBeTruthy();

These changes all seem aimed to improve the robustness and flexibility of model handling within the codebase, especially concerning dynamically adjusting to metadata from fetched models.

@github-actions github-actions bot added the type: bug Something isn't working label Sep 23, 2024
@louis-jan louis-jan changed the title fix: #3558 wrong model metadata import fix: #3558 wrong model metadata import or download from HuggingFace Sep 23, 2024
Copy link
Contributor

github-actions bot commented Sep 23, 2024

Barecheck - Code coverage report

Total: 62.02%

Your code coverage diff: 0.00% ▴

✅ All code changes are covered

@dan-homebrew
Copy link
Contributor

Thank you @louis-jan!

@louis-jan louis-jan merged commit c0b59ec into dev Sep 24, 2024
9 checks passed
@louis-jan louis-jan deleted the fix/3558-3708-3714-wrong-model-metadata-on-import branch September 24, 2024 03:07
@github-actions github-actions bot added this to the v0.5.5 milestone Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
None yet
3 participants