初始化项目,由ModelHub XC社区提供模型
Model: DireDreadlord/GemCod-Sapphire-270M-XM Source: Original Platform
This commit is contained in:
37
.gitattributes
vendored
Normal file
37
.gitattributes
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
*.7z filter=lfs diff=lfs merge=lfs -text
|
||||
*.arrow filter=lfs diff=lfs merge=lfs -text
|
||||
*.bin filter=lfs diff=lfs merge=lfs -text
|
||||
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
||||
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
||||
*.ftz filter=lfs diff=lfs merge=lfs -text
|
||||
*.gz filter=lfs diff=lfs merge=lfs -text
|
||||
*.h5 filter=lfs diff=lfs merge=lfs -text
|
||||
*.joblib filter=lfs diff=lfs merge=lfs -text
|
||||
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
||||
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
||||
*.model filter=lfs diff=lfs merge=lfs -text
|
||||
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
||||
*.npy filter=lfs diff=lfs merge=lfs -text
|
||||
*.npz filter=lfs diff=lfs merge=lfs -text
|
||||
*.onnx filter=lfs diff=lfs merge=lfs -text
|
||||
*.ot filter=lfs diff=lfs merge=lfs -text
|
||||
*.parquet filter=lfs diff=lfs merge=lfs -text
|
||||
*.pb filter=lfs diff=lfs merge=lfs -text
|
||||
*.pickle filter=lfs diff=lfs merge=lfs -text
|
||||
*.pkl filter=lfs diff=lfs merge=lfs -text
|
||||
*.pt filter=lfs diff=lfs merge=lfs -text
|
||||
*.pth filter=lfs diff=lfs merge=lfs -text
|
||||
*.rar filter=lfs diff=lfs merge=lfs -text
|
||||
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
||||
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
||||
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
||||
*.tar filter=lfs diff=lfs merge=lfs -text
|
||||
*.tflite filter=lfs diff=lfs merge=lfs -text
|
||||
*.tgz filter=lfs diff=lfs merge=lfs -text
|
||||
*.wasm filter=lfs diff=lfs merge=lfs -text
|
||||
*.xz filter=lfs diff=lfs merge=lfs -text
|
||||
*.zip filter=lfs diff=lfs merge=lfs -text
|
||||
*.zst filter=lfs diff=lfs merge=lfs -text
|
||||
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
||||
tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
||||
gemcod_logo_c.png filter=lfs diff=lfs merge=lfs -text
|
||||
105
README.md
Normal file
105
README.md
Normal file
@@ -0,0 +1,105 @@
|
||||
---
|
||||
license: gemma
|
||||
datasets:
|
||||
- nphearum/Code-Reasoning-4k
|
||||
language:
|
||||
- en
|
||||
base_model:
|
||||
- google/gemma-3-270m-it
|
||||
pipeline_tag: text-generation
|
||||
tags:
|
||||
- text-generation-inference
|
||||
- code
|
||||
- gemma
|
||||
- SLM
|
||||
---
|
||||
|
||||
|
||||
# GemCod270M - Sapphire - XM (gemma-270m-it-code-reasoning v1.1.0 experimental)
|
||||
|
||||

|
||||
|
||||
GemCod is a lightweight code generation model finetuned using SFT on the base gemma-270m-it model(https://huggingface.co/google/gemma-3-270m-it). It offers accurate and quick(ish) code snippet and long-form code generation in all major programming languages.
|
||||
It's small size (270M parameters) allows it to run comfortably on laptop grade GPUs.
|
||||
|
||||
The Sapphire model represents the next generation of GemCod agents by integrating COT(Chain Of Thought) reasoning capabilities into the standard coding architecture. This almost completely removes the chances of hallucination and allows the model to give highly detailed and specialized explanations and instructions along with its generations.
|
||||
|
||||
It serves as an upgrade from the previous GemCod-Jade-270M model found here (https://huggingface.co/DireDreadlord/GemCod-Jade-270M) whilst only having minor bloat to inference time and space requirements.
|
||||
This model also offers rudimentary Q/A and subject matter expert capabilities on code related subjects.
|
||||
|
||||
**This is the XM(Experimental) variant of the model which is trained on only 2,000 steps on SFT; it may give slightly incorrect outputs on long-form generation.**
|
||||
|
||||
---
|
||||
|
||||
|
||||
**Estimated parameters:** ~270M
|
||||
|
||||
**Architecture:** Gemma3
|
||||
|
||||
**Intended use:** Code snippet and long-form generations from natural language, instruction generation and COT explanations on code snippets
|
||||
|
||||
---
|
||||
|
||||
|
||||
## Training data
|
||||
- Source: code-reasoning-4k dataset (https://huggingface.co/datasets/nphearum/Code-Reasoning-4k)
|
||||
- Rows: ~40,000 rows templated with a custom .jinja chat format
|
||||
- Training: trained for 2,000 steps on an RTX 3050 (4GB VRAM)
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
Install requirements:
|
||||
|
||||
```bash
|
||||
pip install -r requirements.txt
|
||||
pip install transformers datasets accelerate safetensors
|
||||
```
|
||||
|
||||
|
||||
## Usage (Hugging Face Hub)
|
||||
You can load it directly from HuggingFace:
|
||||
|
||||
```python
|
||||
from transformers import AutoTokenizer, AutoModelForCausalLM
|
||||
|
||||
|
||||
tokenizer = AutoTokenizer.from_pretrained("DireDreadlord/GemCod-Sapphire-270M-XM")
|
||||
model = AutoModelForCausalLM.from_pretrained("DireDreadlord/GemCod-Sapphire-270M-XM")
|
||||
model.to(device)
|
||||
model.eval()
|
||||
model.resize_token_embeddings(len(tokenizer))
|
||||
|
||||
|
||||
user_prompt = (
|
||||
"write a bubble sort algorithm in cpp."
|
||||
"Please think step by step and show your chain-of-thought before the final code." #<-- comment out this line to disable COT
|
||||
)
|
||||
|
||||
messages = [{"role": "user", "content": user_prompt}]
|
||||
|
||||
|
||||
inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt")
|
||||
inputs = {k: v.to(device) for k, v in inputs.items()}
|
||||
|
||||
|
||||
with torch.no_grad():
|
||||
outputs = model.generate(
|
||||
**inputs,
|
||||
max_new_tokens=1024,
|
||||
do_sample=False,
|
||||
num_beams=1,
|
||||
pad_token_id=tokenizer.eos_token_id,
|
||||
eos_token_id=tokenizer.eos_token_id,
|
||||
use_cache=False,
|
||||
)
|
||||
|
||||
|
||||
prompt_len = inputs["input_ids"].shape[1]
|
||||
generated_ids = outputs[0, prompt_len:]
|
||||
print(tokenizer.decode(generated_ids.tolist(), skip_special_tokens=True))
|
||||
```
|
||||
**For optimal long-form generation along with COT, set `max_new_tokens=2048`**
|
||||
|
||||
## Limitations
|
||||
- Model for experimental use only; users should employ it as such under license.
|
||||
47
chat_template.jinja
Normal file
47
chat_template.jinja
Normal file
@@ -0,0 +1,47 @@
|
||||
{{ bos_token }}
|
||||
{%- if messages[0]['role'] == 'system' -%}
|
||||
{%- if messages[0]['content'] is string -%}
|
||||
{%- set first_user_prefix = messages[0]['content'] + '
|
||||
|
||||
' -%}
|
||||
{%- else -%}
|
||||
{%- set first_user_prefix = messages[0]['content'][0]['text'] + '
|
||||
|
||||
' -%}
|
||||
{%- endif -%}
|
||||
{%- set loop_messages = messages[1:] -%}
|
||||
{%- else -%}
|
||||
{%- set first_user_prefix = "" -%}
|
||||
{%- set loop_messages = messages -%}
|
||||
{%- endif -%}
|
||||
{%- for message in loop_messages -%}
|
||||
{%- if (message['role'] == 'user') != (loop.index0 % 2 == 0) -%}
|
||||
{{ raise_exception("Conversation roles must alternate user/assistant/user/assistant/...") }}
|
||||
{%- endif -%}
|
||||
{%- if (message['role'] == 'assistant') -%}
|
||||
{%- set role = "model" -%}
|
||||
{%- else -%}
|
||||
{%- set role = message['role'] -%}
|
||||
{%- endif -%}
|
||||
{{ '<start_of_turn>' + role + '
|
||||
' + (first_user_prefix if loop.first else "") }}
|
||||
{%- if message['content'] is string -%}
|
||||
{{ message['content'] | trim }}
|
||||
{%- elif message['content'] is iterable -%}
|
||||
{%- for item in message['content'] -%}
|
||||
{%- if item['type'] == 'image' -%}
|
||||
{{ '<start_of_image>' }}
|
||||
{%- elif item['type'] == 'text' -%}
|
||||
{{ item['text'] | trim }}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
{%- else -%}
|
||||
{{ raise_exception("Invalid content type") }}
|
||||
{%- endif -%}
|
||||
{{ '<end_of_turn>
|
||||
' }}
|
||||
{%- endfor -%}
|
||||
{%- if add_generation_prompt -%}
|
||||
{{'<start_of_turn>model
|
||||
'}}
|
||||
{%- endif -%}
|
||||
62
config.json
Normal file
62
config.json
Normal file
@@ -0,0 +1,62 @@
|
||||
{
|
||||
"_sliding_window_pattern": 6,
|
||||
"architectures": [
|
||||
"Gemma3ForCausalLM"
|
||||
],
|
||||
"attention_bias": false,
|
||||
"attention_dropout": 0.0,
|
||||
"attn_logit_softcapping": null,
|
||||
"bos_token_id": 2,
|
||||
"dtype": "bfloat16",
|
||||
"eos_token_id": 1,
|
||||
"final_logit_softcapping": null,
|
||||
"head_dim": 256,
|
||||
"hidden_activation": "gelu_pytorch_tanh",
|
||||
"hidden_size": 640,
|
||||
"initializer_range": 0.02,
|
||||
"intermediate_size": 2048,
|
||||
"layer_types": [
|
||||
"sliding_attention",
|
||||
"sliding_attention",
|
||||
"sliding_attention",
|
||||
"sliding_attention",
|
||||
"sliding_attention",
|
||||
"full_attention",
|
||||
"sliding_attention",
|
||||
"sliding_attention",
|
||||
"sliding_attention",
|
||||
"sliding_attention",
|
||||
"sliding_attention",
|
||||
"full_attention",
|
||||
"sliding_attention",
|
||||
"sliding_attention",
|
||||
"sliding_attention",
|
||||
"sliding_attention",
|
||||
"sliding_attention",
|
||||
"full_attention"
|
||||
],
|
||||
"max_position_embeddings": 32768,
|
||||
"model_type": "gemma3_text",
|
||||
"num_attention_heads": 4,
|
||||
"num_hidden_layers": 18,
|
||||
"num_key_value_heads": 1,
|
||||
"pad_token_id": 0,
|
||||
"query_pre_attn_scalar": 256,
|
||||
"rms_norm_eps": 1e-06,
|
||||
"rope_parameters": {
|
||||
"full_attention": {
|
||||
"rope_theta": 1000000.0,
|
||||
"rope_type": "default"
|
||||
},
|
||||
"sliding_attention": {
|
||||
"rope_theta": 10000.0,
|
||||
"rope_type": "default"
|
||||
}
|
||||
},
|
||||
"sliding_window": 512,
|
||||
"tie_word_embeddings": true,
|
||||
"transformers_version": "5.9.0",
|
||||
"use_bidirectional_attention": false,
|
||||
"use_cache": false,
|
||||
"vocab_size": 262145
|
||||
}
|
||||
3
gemcod_logo_c.png
Normal file
3
gemcod_logo_c.png
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:74623faa5b943af3ada82300b8b3058eac1eede3940ec712a3f1f3424538e473
|
||||
size 2675237
|
||||
13
generation_config.json
Normal file
13
generation_config.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"bos_token_id": 2,
|
||||
"cache_implementation": "hybrid",
|
||||
"do_sample": true,
|
||||
"eos_token_id": [
|
||||
1,
|
||||
106
|
||||
],
|
||||
"pad_token_id": 0,
|
||||
"top_k": 64,
|
||||
"top_p": 0.95,
|
||||
"transformers_version": "5.9.0"
|
||||
}
|
||||
3
model.safetensors
Normal file
3
model.safetensors
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:ad8a061ac9de164890249b5de7e7ab62b37eae0e2be6591f8d3c931d5b154dc9
|
||||
size 536224336
|
||||
13
requirements.txt
Normal file
13
requirements.txt
Normal file
@@ -0,0 +1,13 @@
|
||||
torch
|
||||
numpy
|
||||
tiktoken
|
||||
datasets
|
||||
transformers
|
||||
peft
|
||||
bitsandbytes
|
||||
tqdm
|
||||
matplotlib
|
||||
safetensors
|
||||
huggingface_hub
|
||||
accelerate
|
||||
trl
|
||||
3
tokenizer.json
Normal file
3
tokenizer.json
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:daab2354f8a74e70d70b4d1f804939b68a8c9624dd06cb7858e52dd8970e9726
|
||||
size 33384567
|
||||
25
tokenizer_config.json
Normal file
25
tokenizer_config.json
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"backend": "tokenizers",
|
||||
"boi_token": "<start_of_image>",
|
||||
"bos_token": "<bos>",
|
||||
"clean_up_tokenization_spaces": false,
|
||||
"eoi_token": "<end_of_image>",
|
||||
"eos_token": "<eos>",
|
||||
"image_token": "<image_soft_token>",
|
||||
"is_local": false,
|
||||
"local_files_only": false,
|
||||
"mask_token": "<mask>",
|
||||
"model_max_length": 1000000000000000019884624838656,
|
||||
"model_specific_special_tokens": {
|
||||
"boi_token": "<start_of_image>",
|
||||
"eoi_token": "<end_of_image>",
|
||||
"image_token": "<image_soft_token>"
|
||||
},
|
||||
"pad_token": "<pad>",
|
||||
"padding_side": "left",
|
||||
"sp_model_kwargs": null,
|
||||
"spaces_between_special_tokens": false,
|
||||
"tokenizer_class": "GemmaTokenizer",
|
||||
"unk_token": "<unk>",
|
||||
"use_default_system_prompt": false
|
||||
}
|
||||
3
training_args.bin
Normal file
3
training_args.bin
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:87f15dab535d410b5130fef610ff8ddd5c4288b83e66d1609dffd9863b1a3f7d
|
||||
size 5304
|
||||
Reference in New Issue
Block a user