From a294322ff40c44e1c02db9b41bf15d21160af8c4 Mon Sep 17 00:00:00 2001 From: Hoang Ha <64120343+hahuyhoang411@users.noreply.github.com> Date: Fri, 1 Nov 2024 10:39:59 +0100 Subject: [PATCH] Chore: Fix (#50) * fix typo * fix workflow * fix * test * test * workflow --- .github/workflows/create-model-yml.yml | 42 ++++++++++++-------------- README.md | 2 +- 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/.github/workflows/create-model-yml.yml b/.github/workflows/create-model-yml.yml index 0137649..4554ba4 100644 --- a/.github/workflows/create-model-yml.yml +++ b/.github/workflows/create-model-yml.yml @@ -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|>,)" required: true @@ -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 }} @@ -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) @@ -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") @@ -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: diff --git a/README.md b/README.md index 45433b4..0f7949d 100644 --- a/README.md +++ b/README.md @@ -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