Skip to content

Commit

Permalink
Chore: Fix (#50)
Browse files Browse the repository at this point in the history
* fix typo

* fix workflow

* fix

* test

* test

* workflow
  • Loading branch information
hahuyhoang411 authored Nov 1, 2024
1 parent 62e62a2 commit a294322
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 24 deletions.
42 changes: 19 additions & 23 deletions .github/workflows/create-model-yml.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,21 @@ on:
description: "Name of the model to create (will be used in repo name and files)"
required: true
type: string
model_variant:
description: "Model variant (e.g., 8b, 13b) - will be used in default field"
required: true
type: string
default: "8b"
prompt_template:
description: "Prompt template for the model"
required: true
type: string
default: "<|im_start|>system\n{system_message}<|im_end|>\n<|im_start|>user\n{prompt}<|im_end|>\n<|im_start|>assistant"
default: |
<|im_start|>system
{system_message}<|im_end|>
<|im_start|>user
{prompt}<|im_end|>
<|im_start|>assistant
stop_tokens:
description: "Stop tokens for the model (comma-separated, e.g., <|im_end|>,</s>)"
required: true
Expand All @@ -22,9 +32,11 @@ on:
required: true
type: string
default: "llama-cpp"

env:
USER_NAME: cortexso
MODEL_NAME: ${{ inputs.model_name }}
MODEL_VARIANT: ${{ inputs.model_variant }}
PROMPT_TEMPLATE: ${{ inputs.prompt_template }}
STOP_TOKENS: ${{ inputs.stop_tokens }}
ENGINE: ${{ inputs.engine }}
Expand Down Expand Up @@ -69,8 +81,8 @@ jobs:
pass
def custom_str_representer(dumper, data):
if isinstance(data, str):
return dumper.represent_scalar('tag:yaml.org,2002:str', data, style='')
if isinstance(data, str) and '\n' in data:
return dumper.represent_scalar('tag:yaml.org,2002:str', data, style='|')
return SafeRepresenter.represent_str(dumper, data)
CustomDumper.add_representer(str, custom_str_representer)
Expand All @@ -91,24 +103,8 @@ jobs:
if subsection:
file.write(f"# BEGIN {subsection}\n")
# Special handling for prompt_template to ensure it's a single line with preserved \n
if 'prompt_template' in content:
# Create a copy of the content to modify
modified_content = content.copy()
# Convert the prompt template to a literal string that preserves \n
prompt_template = modified_content['prompt_template']
# Remove the prompt_template from the content to handle it separately
del modified_content['prompt_template']
# Dump the rest of the content
yaml_content = yaml.dump(modified_content, Dumper=CustomDumper, default_flow_style=False, sort_keys=False)
file.write(yaml_content)
# Write the prompt_template separately with proper escaping
file.write(f'prompt_template: "{prompt_template}"\n')
else:
yaml_content = yaml.dump(content, Dumper=CustomDumper, default_flow_style=False, sort_keys=False)
file.write(yaml_content)
yaml_content = yaml.dump(content, Dumper=CustomDumper, default_flow_style=False, sort_keys=False)
file.write(yaml_content)
if subsection:
file.write(f"# END {subsection}\n")
Expand Down Expand Up @@ -173,11 +169,11 @@ jobs:
write_section(f, required_load, '', 'REQUIRED')
f.write("# END MODEL LOAD PARAMETERS\n")
# Create metadata.yml
# Create metadata.yml with dynamic default field
metadata_content = {
'version': 1,
'name': os.environ['MODEL_NAME'],
'default': '8b-gguf-q4-km'
'default': f"{os.environ['MODEL_VARIANT']}-gguf-q4-km"
}
with open('metadata.yml', 'w') as f:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ This step will create a model repository on [Cortexso's Hugging Face account](ht
3. Click `Run workflow` dropdown
4. Fill in the required information:
- **`source_model_id`**: The source HuggingFace model ID (e.g., meta-llama/Meta-Llama-3.1-8B-Instruct)
- **`**source_model_size`**: The model size (e.g., 8b)
- **`source_model_size`**: The model size (e.g., 8b)
- **`target_model_id`**: The target HuggingFace model ID
- **`quantization_level`**: Quantization level (e.g., 'q4-km') or 'all' for all levels
5. Click `Run workflow` button to start the conversion
Expand Down

0 comments on commit a294322

Please sign in to comment.