Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
492a178
feat(huggingface): Added first version of a true conversion of the mo…
BlueCrescent Feb 20, 2025
84ac2b7
refactor(conversion): convert_gpt2
flxst Feb 21, 2025
d516469
fix(huggingface): Set correct model_type in GPT2Config.
BlueCrescent Feb 21, 2025
49191d1
refactor(huggingface): Shortened some long lines.
BlueCrescent Feb 21, 2025
7332916
feat(huggingface): When converting gpt2 now all the necessary model c…
BlueCrescent Feb 21, 2025
a390289
docs(huggingface): Added docstrings for conversion script.
BlueCrescent Feb 21, 2025
0e4310d
chore(getting_started): update config (no bias, layer norm, swiglu, p…
flxst Feb 21, 2025
d3ab1b5
test(conversion): apply checkpoint conversion based on getting starte…
flxst Feb 21, 2025
c01a1fe
test(getting_started): move wandb directory to data (so that it gets …
flxst Feb 24, 2025
85411be
refactor(getting_started): refactoring (folder structure) and general…
flxst Feb 24, 2025
262f06c
fix(huggingface): Added missing import.
BlueCrescent Feb 24, 2025
6564452
refactor(huggingface): Minor code improvement.
BlueCrescent Feb 24, 2025
f7e558c
fix(getting_started): capture subprocess errors properly + bug fix
flxst Feb 24, 2025
cb6259e
chore: Merge branch 'conversion_modalities_to_huggingface' of https:/…
flxst Feb 24, 2025
01c75ec
test(conversion): check checkpoint conversion based on getting starte…
flxst Feb 24, 2025
b119726
feat(huggingface): Added handling of additional config settings to co…
BlueCrescent Feb 24, 2025
286b37f
test(huggingface): Added additional tests for conversion functions.
BlueCrescent Feb 24, 2025
3948575
fix(checkpointing): Fixed warning.
BlueCrescent Feb 25, 2025
8991797
test(huggingface): Fixed model output comparison test.
BlueCrescent Feb 25, 2025
e91633d
refactor(huggingface): Split conversion logic into multiple files.
BlueCrescent Feb 25, 2025
d43b8d2
test(huggingface): Additional tests and some refactoring.
BlueCrescent Feb 25, 2025
836e934
revert(checkpointing): For now, forcing weights_only is not supposed …
BlueCrescent Feb 25, 2025
f4cc962
fix(conversion): check that criteria for conversion are fulfilled
flxst Feb 25, 2025
335cc0e
chore: Merge branch 'conversion_modalities_to_huggingface' of https:/…
flxst Feb 25, 2025
cd75707
docs(huggingface): Removed sentence in doc string that is not true yet.
BlueCrescent Feb 25, 2025
75524d4
test(huggingface): Added some variety in bias settings of test config…
BlueCrescent Feb 25, 2025
cf3cba6
fix(huggingface): The config conversion now only allows all norms to …
BlueCrescent Mar 4, 2025
9707027
docs(huggingface): small fix
BlueCrescent Mar 4, 2025
60bab8a
refactor(huggingface): missing type hint
BlueCrescent Mar 5, 2025
000a9fa
test(huggingface): Added one additional test and refactored some others.
BlueCrescent Mar 6, 2025
e74f5fb
chore: Merge remote-tracking branch 'origin/main' into conversion_mod…
BlueCrescent Mar 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor(huggingface): Minor code improvement.
  • Loading branch information
BlueCrescent committed Feb 24, 2025
commit 6564452db5505d3c061ef9236ea9afa76f262168
9 changes: 8 additions & 1 deletion src/modalities/conversion/gpt2/convert_gpt2.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,20 +198,27 @@ def _copy_weights_base_modules(m1: nn.Linear | nn.LayerNorm, m2: nn.Linear | nn.


def _transfer_model_code(output_dir: str):
"""Copies the required model code to the output directory.
"""Copies the required model code to the output directory and replaces modalities imports.
This allows the converted model to be used without the modalities package via:
>>> from transformers import AutoModelForCausalLM
>>> model = AutoModelForCausalLM.from_pretrained("path/to/converted/model", trust_remote_code=True)

Args:
output_dir (str): Directory of the converted model.
"""
_copy_model_files(output_dir)
_change_modalities_import_to_relative_import(output_dir)


def _copy_model_files(output_dir: str):
source_dir = os.path.dirname(__file__)
modeling_gpt2_path = os.path.join(source_dir, "modeling_gpt2.py")
configuration_gpt2_path = os.path.join(source_dir, "configuration_gpt2.py")
shutil.copy(modeling_gpt2_path, output_dir)
shutil.copy(configuration_gpt2_path, output_dir)


def _change_modalities_import_to_relative_import(output_dir: str):
target_modeling_file = os.path.join(output_dir, "modeling_gpt2.py")
with open(target_modeling_file, "r") as file:
content = file.read()
Expand Down