Upload fine-tuned model and deployment files
Browse filesFiles changed (26)
- README.mdAdded+41
- added_tokens.jsonAdded+6
- app.pyAdded+56
- checkpoint-18/added_tokens.jsonAdded+6
- checkpoint-18/config.jsonAdded+40
- checkpoint-18/generation_config.jsonAdded+10
- checkpoint-18/merges.txtAdded
- checkpoint-18/model.safetensorsAdded+3
- checkpoint-18/optimizer.ptAdded+3
- checkpoint-18/rng_state.pthAdded+3
- checkpoint-18/scheduler.ptAdded+3
- checkpoint-18/special_tokens_map.jsonAdded+30
- checkpoint-18/tokenizer.jsonAdded
- checkpoint-18/tokenizer_config.jsonAdded+49
- checkpoint-18/trainer_state.jsonAdded+65
- checkpoint-18/training_args.binAdded+3
- checkpoint-18/vocab.jsonAdded
- config.jsonAdded+40
- generation_config.jsonAdded+10
- merges.txtAdded
- model.safetensorsAdded+3
- special_tokens_map.jsonAdded+30
- tokenizer.jsonAdded
- tokenizer_config.jsonAdded+49
- training_args.binAdded+3
- vocab.jsonAdded
1234567891011121314151617181920212223242526272829303132333435363738394041
# Fine-tuned Code Model for Vite, React, Next.js, Node.js, Python, and Go
This model is a fine-tuned version of [microsoft/CodeGPT-small-java-adaptedgpt2](https://huggingface.co/microsoft/CodeGPT-small-java-adaptedgpt2)adapted for code understanding and generation tasks across several technologies:Vite, React, Next.js, Node.js, Python, and Go.
The model was fine-tuned on code data extracted from private GitHub repositories.
## How to use
You can load and use this model with the `transformers` library:
```pythonfrom transformers import AutoModelForCausalLM, AutoTokenizer
model_path = "." # Or the repository ID after pushing to Hugging Face Hubtokenizer = AutoTokenizer.from_pretrained(model_path)model = AutoModelForCausalLM.from_pretrained(model_path)
# Example inferenceinput_text = "def fibonacci("input_ids = tokenizer(input_text, return_tensors="pt").input_idsoutput_ids = model.generate(input_ids, max_length=50)output_text = tokenizer.decode(output_ids[0], skip_special_tokens=True)print(output_text)```
## Fine-tuning Details
- **Base Model:** microsoft/CodeGPT-small-java-adaptedgpt2- **Fine-tuning Data:** Code from private GitHub repositories focusing on Vite, React, Next.js, Node.js, Python, and Go.- **Training Parameters:** (Include key parameters from TrainingArguments here, e.g., epochs, batch size) - Number of Epochs: 3 - Per Device Train Batch Size: 2 - Learning Rate: 2e-5
## Limitations
- This model was fine-tuned on a limited private dataset and may not generalize well to all code scenarios or languages.- The model size is optimized for deployment on Hugging Face Spaces with a 2GB limit, which might impact its performance compared to larger models.123456{ "</s>": 50258, "<pad>": 50257, "<s>": 50259, "<|UNKNOWN|>": 50260}1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
from transformers import AutoModelForCausalLM, AutoTokenizerimport torchimport gradio as gr # Example using Gradio for a simple web interface
# Define the model path (relative to the Space root)model_path = "." # Model and tokenizer files are expected in the root
# Load the model and tokenizertry: tokenizer = AutoTokenizer.from_pretrained(model_path) model = AutoModelForCausalLM.from_pretrained(model_path) print("Model and tokenizer loaded successfully.")except Exception as e: print(f"Error loading model or tokenizer: {e}") # Exit or handle error appropriately in a real app exit()
def generate_code(prompt, max_length=100): """Generates code based on a given prompt.""" try: input_ids = tokenizer(prompt, return_tensors="pt").input_ids # Ensure input_ids are on the same device as the model if using GPU if torch.cuda.is_available(): model.to('cuda') input_ids = input_ids.to('cuda')
# Generate text output_ids = model.generate(input_ids, max_length=max_length, num_return_sequences=1, no_repeat_ngram_size=2)
# Decode the output # Decode only the newly generated part generated_text = tokenizer.decode(output_ids[0][len(input_ids[0]):], skip_special_tokens=True) return prompt + generated_text # Return prompt + generated part
except Exception as e: return f"Error generating code: {e}"
# Create a simple Gradio interfaceiface = gr.Interface( fn=generate_code, inputs=gr.Textbox(lines=2, label="Enter code prompt"), outputs=gr.Textbox(label="Generated code"), title="Code Generation Model", description="Generate code snippets based on your input prompt.")
if __name__ == "__main__": # To run this locally for testing, you would typically use iface.launch() # For Hugging Face Spaces, the app is automatically run based on the file name (app.py) # and the presence of a Gradio or Streamlit interface. # We'll keep the launch call here for local testing purposes if needed. # iface.launch() pass # In a real Space, this part is handled by the platform.
123456{ "</s>": 50258, "<pad>": 50257, "<s>": 50259, "<|UNKNOWN|>": 50260}12345678910111213141516171819202122232425262728293031323334353637383940{ "activation_function": "gelu_new", "architectures": [ "GPT2LMHeadModel" ], "attn_pdrop": 0.1, "bos_token_id": 50259, "dtype": "float32", "embd_pdrop": 0.1, "eos_token_id": 50258, "gradient_checkpointing": false, "initializer_range": 0.02, "layer_norm_epsilon": 1e-05, "model_type": "gpt2", "n_ctx": 1024, "n_embd": 768, "n_head": 12, "n_inner": null, "n_layer": 12, "n_positions": 1024, "pad_token_id": 50257, "reorder_and_upcast_attn": false, "resid_pdrop": 0.1, "scale_attn_by_inverse_layer_idx": false, "scale_attn_weights": true, "summary_activation": null, "summary_first_dropout": 0.1, "summary_proj_to_labels": true, "summary_type": "cls_index", "summary_use_proj": true, "task_specific_params": { "text-generation": { "do_sample": true, "max_length": 50 } }, "transformers_version": "4.56.1", "use_cache": true, "vocab_size": 50261}12345678910{ "_from_model_config": true, "bos_token_id": 50259, "eos_token_id": [ 50258, 50256 ], "pad_token_id": 50257, "transformers_version": "4.56.1"}123version https://git-lfs.github.com/spec/v1oid sha256:e03d69f49f3a625693ee56c05915faa4215d4ad5f308502da7b46be957ae3ae1size 497786496123version https://git-lfs.github.com/spec/v1oid sha256:2a994154b2732d52f3ed0bd5fa8df291e9a87368a8e108b0023427cdaa0305c6size 995663179123version https://git-lfs.github.com/spec/v1oid sha256:9492f3835a9a92624197a5f40df85f402dddf1c5ba93599dda25603402e83216size 14455123version https://git-lfs.github.com/spec/v1oid sha256:9f267c7943bf40c58210967998ceee4b979c120bc3f98ef1861ed7ed4b01d0b8size 1465123456789101112131415161718192021222324252627282930{ "bos_token": { "content": "<s>", "lstrip": false, "normalized": true, "rstrip": false, "single_word": false }, "eos_token": { "content": "</s>", "lstrip": false, "normalized": true, "rstrip": false, "single_word": false }, "pad_token": { "content": "<pad>", "lstrip": false, "normalized": true, "rstrip": false, "single_word": false }, "unk_token": { "content": "<|UNKNOWN|>", "lstrip": false, "normalized": true, "rstrip": false, "single_word": false }}12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849{ "add_bos_token": false, "add_prefix_space": false, "added_tokens_decoder": { "50257": { "content": "<pad>", "lstrip": false, "normalized": true, "rstrip": false, "single_word": false, "special": true }, "50258": { "content": "</s>", "lstrip": false, "normalized": true, "rstrip": false, "single_word": false, "special": true }, "50259": { "content": "<s>", "lstrip": false, "normalized": true, "rstrip": false, "single_word": false, "special": true }, "50260": { "content": "<|UNKNOWN|>", "lstrip": false, "normalized": true, "rstrip": false, "single_word": false, "special": true } }, "bos_token": "<s>", "clean_up_tokenization_spaces": false, "do_lower_case": false, "eos_token": "</s>", "errors": "replace", "extra_special_tokens": {}, "full_tokenizer_file": null, "model_max_length": 1000000000000000019884624838656, "pad_token": "<pad>", "tokenizer_class": "GPT2Tokenizer", "unk_token": "<|UNKNOWN|>"}1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465{ "best_global_step": null, "best_metric": null, "best_model_checkpoint": null, "epoch": 3.0, "eval_steps": 500, "global_step": 18, "is_hyper_param_search": false, "is_local_process_zero": true, "is_world_process_zero": true, "log_history": [ { "epoch": 1.0, "eval_loss": 0.9348117709159851, "eval_runtime": 2.2844, "eval_samples_per_second": 1.313, "eval_steps_per_second": 0.876, "step": 6 }, { "epoch": 1.6666666666666665, "grad_norm": 37.8013916015625, "learning_rate": 1e-05, "loss": 3.5265, "step": 10 }, { "epoch": 2.0, "eval_loss": 0.6782895922660828, "eval_runtime": 2.283, "eval_samples_per_second": 1.314, "eval_steps_per_second": 0.876, "step": 12 }, { "epoch": 3.0, "eval_loss": 0.6249104738235474, "eval_runtime": 2.1405, "eval_samples_per_second": 1.402, "eval_steps_per_second": 0.934, "step": 18 } ], "logging_steps": 10, "max_steps": 18, "num_input_tokens_seen": 0, "num_train_epochs": 3, "save_steps": 500, "stateful_callbacks": { "TrainerControl": { "args": { "should_epoch_stop": false, "should_evaluate": false, "should_log": false, "should_save": true, "should_training_stop": true }, "attributes": {} } }, "total_flos": 2155659264000.0, "train_batch_size": 2, "trial_name": null, "trial_params": null}123version https://git-lfs.github.com/spec/v1oid sha256:2cfe1a2b998b5590e8b9424c6c30b1de2c5d353245465cf078ec428894df9d96size 571312345678910111213141516171819202122232425262728293031323334353637383940{ "activation_function": "gelu_new", "architectures": [ "GPT2LMHeadModel" ], "attn_pdrop": 0.1, "bos_token_id": 50259, "dtype": "float32", "embd_pdrop": 0.1, "eos_token_id": 50258, "gradient_checkpointing": false, "initializer_range": 0.02, "layer_norm_epsilon": 1e-05, "model_type": "gpt2", "n_ctx": 1024, "n_embd": 768, "n_head": 12, "n_inner": null, "n_layer": 12, "n_positions": 1024, "pad_token_id": 50257, "reorder_and_upcast_attn": false, "resid_pdrop": 0.1, "scale_attn_by_inverse_layer_idx": false, "scale_attn_weights": true, "summary_activation": null, "summary_first_dropout": 0.1, "summary_proj_to_labels": true, "summary_type": "cls_index", "summary_use_proj": true, "task_specific_params": { "text-generation": { "do_sample": true, "max_length": 50 } }, "transformers_version": "4.56.1", "use_cache": true, "vocab_size": 50261}12345678910{ "_from_model_config": true, "bos_token_id": 50259, "eos_token_id": [ 50258, 50256 ], "pad_token_id": 50257, "transformers_version": "4.56.1"}123version https://git-lfs.github.com/spec/v1oid sha256:e03d69f49f3a625693ee56c05915faa4215d4ad5f308502da7b46be957ae3ae1size 497786496123456789101112131415161718192021222324252627282930{ "bos_token": { "content": "<s>", "lstrip": false, "normalized": true, "rstrip": false, "single_word": false }, "eos_token": { "content": "</s>", "lstrip": false, "normalized": true, "rstrip": false, "single_word": false }, "pad_token": { "content": "<pad>", "lstrip": false, "normalized": true, "rstrip": false, "single_word": false }, "unk_token": { "content": "<|UNKNOWN|>", "lstrip": false, "normalized": true, "rstrip": false, "single_word": false }}12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849{ "add_bos_token": false, "add_prefix_space": false, "added_tokens_decoder": { "50257": { "content": "<pad>", "lstrip": false, "normalized": true, "rstrip": false, "single_word": false, "special": true }, "50258": { "content": "</s>", "lstrip": false, "normalized": true, "rstrip": false, "single_word": false, "special": true }, "50259": { "content": "<s>", "lstrip": false, "normalized": true, "rstrip": false, "single_word": false, "special": true }, "50260": { "content": "<|UNKNOWN|>", "lstrip": false, "normalized": true, "rstrip": false, "single_word": false, "special": true } }, "bos_token": "<s>", "clean_up_tokenization_spaces": false, "do_lower_case": false, "eos_token": "</s>", "errors": "replace", "extra_special_tokens": {}, "full_tokenizer_file": null, "model_max_length": 1000000000000000019884624838656, "pad_token": "<pad>", "tokenizer_class": "GPT2Tokenizer", "unk_token": "<|UNKNOWN|>"}123version https://git-lfs.github.com/spec/v1oid sha256:2cfe1a2b998b5590e8b9424c6c30b1de2c5d353245465cf078ec428894df9d96size 5713README.mdAdded+41
added_tokens.jsonAdded+6
app.pyAdded+56
checkpoint-18/added_tokens.jsonAdded+6
checkpoint-18/config.jsonAdded+40
checkpoint-18/generation_config.jsonAdded+10
checkpoint-18/merges.txtAdded
checkpoint-18/model.safetensorsAdded+3
checkpoint-18/optimizer.ptAdded+3
checkpoint-18/rng_state.pthAdded+3
checkpoint-18/scheduler.ptAdded+3
checkpoint-18/special_tokens_map.jsonAdded+30
checkpoint-18/tokenizer.jsonAdded
checkpoint-18/tokenizer_config.jsonAdded+49
checkpoint-18/trainer_state.jsonAdded+65
checkpoint-18/training_args.binAdded+3
checkpoint-18/vocab.jsonAdded
config.jsonAdded+40
generation_config.jsonAdded+10
merges.txtAdded
model.safetensorsAdded+3
special_tokens_map.jsonAdded+30
tokenizer.jsonAdded
tokenizer_config.jsonAdded+49
training_args.binAdded+3
vocab.jsonAdded