Text Generation
Transformers
English
CodeT5
text2text-generation
code
python
codet5
code-generation
code-refactoring
Instructions to use S-Dreamer/PyCodeT5 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use S-Dreamer/PyCodeT5 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="S-Dreamer/PyCodeT5")# Load model directly from transformers import AutoModelForSeq2SeqLM model = AutoModelForSeq2SeqLM.from_pretrained("S-Dreamer/PyCodeT5", dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use S-Dreamer/PyCodeT5 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "S-Dreamer/PyCodeT5" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "S-Dreamer/PyCodeT5", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/S-Dreamer/PyCodeT5
- SGLang
How to use S-Dreamer/PyCodeT5 with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "S-Dreamer/PyCodeT5" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "S-Dreamer/PyCodeT5", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "S-Dreamer/PyCodeT5" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "S-Dreamer/PyCodeT5", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use S-Dreamer/PyCodeT5 with Docker Model Runner:
docker model run hf.co/S-Dreamer/PyCodeT5
| license: apache-2.0 | |
| language: | |
| - en | |
| library_name: transformers | |
| pipeline_tag: text-generation | |
| tags: | |
| - code | |
| - python | |
| - codet5 | |
| - code-generation | |
| - code-refactoring | |
| datasets: | |
| - S-Dreamer/PyCodeT5 | |
| - flytech/python-codes-25k | |
| - jinaai/code_exercises | |
| <p align="left"> | |
| <img src="PyCodeT5.png" alt="Python AI Icon" width="25%"> | |
| </p> | |
| # Model Card for PyCodeT5 | |
| CodeT5 Python Functions is a specialized variant of the CodeT5 model, fine-tuned for generating and understanding Python functions. It is designed to assist in transforming natural language descriptions into functional Python code, as well as optimizing existing code by applying Pythonic conventions and best practices. This model can generate function definitions, implement logical flows, and assist with debugging and refactoring Python code. It is ideal for developers, learners, and AI-powered programming assistants. | |
| --- | |
| ## Table of Contents | |
| - [Model Card for PyCodeT5](#model-card-for-pycodet5) | |
| - [Table of Contents](#table-of-contents) | |
| - [Model Details](#model-details) | |
| - [Model Description](#model-description) | |
| - [Uses](#uses) | |
| - [Direct Use](#direct-use) | |
| - [Downstream Use [Optional]](#downstream-use-optional) | |
| - [Out-of-Scope Use](#out-of-scope-use) | |
| - [Bias, Risks, and Limitations](#bias-risks-and-limitations) | |
| - [Recommendations](#recommendations) | |
| - [Training Details](#training-details) | |
| - [Training Data](#training-data) | |
| - [Training Procedure](#training-procedure) | |
| - [Preprocessing](#preprocessing) | |
| - [Speeds, Sizes, Times](#speeds-sizes-times) | |
| - [Evaluation](#evaluation) | |
| - [Testing Data, Factors & Metrics](#testing-data-factors--metrics) | |
| - [Testing Data](#testing-data) | |
| - [Factors](#factors) | |
| - [Metrics](#metrics) | |
| - [Results](#results) | |
| - [Model Examination](#model-examination) | |
| - [Environmental Impact](#environmental-impact) | |
| - [Technical Specifications [optional]](#technical-specifications-optional) | |
| - [Model Architecture and Objective](#model-architecture-and-objective) | |
| - [Compute Infrastructure](#compute-infrastructure) | |
| - [Hardware](#hardware) | |
| - [Software](#software) | |
| - [Citation](#citation) | |
| - [Glossary [optional]](#glossary-optional) | |
| - [More Information [optional]](#more-information-optional) | |
| - [Model Card Authors [optional]](#model-card-authors-optional) | |
| - [Model Card Contact](#model-card-contact) | |
| - [How to Get Started with the Model](#how-to-get-started-with-the-model) | |
| --- | |
| ## Model Details | |
| ### Model Description | |
| CodeT5 Python Functions is a specialized variant of the CodeT5 model, fine-tuned for generating and understanding Python functions. It is designed to assist in transforming natural language descriptions into functional Python code, as well as optimizing existing code by applying Pythonic conventions and best practices. This model can generate function definitions, implement logical flows, and assist with debugging and refactoring Python code. It is ideal for developers, learners, and AI-powered programming assistants. | |
| - **Developed by:** More information needed | |
| - **Shared by [Optional]:** More information needed | |
| - **Model type:** Language model | |
| - **Language(s) (NLP):** en | |
| - **License:** apache-2.0 | |
| - **Parent Model:** More information needed | |
| - **Resources for more information:** | |
| - [GitHub Repo](https://github.com/Salesforce/CodeT5) | |
| - [Associated Paper](2103.02720) | |
| --- | |
| ## Uses | |
| ### Direct Use | |
| - **Generate Python Functions:** Convert natural language descriptions into functional Python code. | |
| - **Optimize Python Code:** Apply Pythonic conventions and best practices to improve code quality. | |
| - **Assist with Debugging and Refactoring:** Help users identify and fix issues in Python code. | |
| ### Downstream Use [Optional] | |
| - **Integration with AI-powered programming assistants:** Use as a backend model for intelligent code completion or review tools. | |
| ### Out-of-Scope Use | |
| - **Non-Python Code Generation:** This model is specifically trained for Python code generation and is not suitable for other languages. | |
| - **Sensitive Applications:** It is not recommended to use this model in mission-critical systems or environments where safety or security is paramount. | |
| --- | |
| ## Bias, Risks, and Limitations | |
| This model, like other large language models, may reflect biases present in the data used during training. For example, it may generate code that includes harmful stereotypes or unfair practices in certain contexts. | |
| ### Recommendations | |
| - **Careful Use in Sensitive Domains:** When applying the model in high-risk or security-critical environments, extra validation and review processes should be in place. | |
| - **Code Review:** Always ensure that code generated by this model undergoes thorough human review, especially in sensitive or production environments. | |
| --- | |
| ## Training Details | |
| ### Training Data | |
| The model was fine-tuned on a dataset of Python code from various open-source repositories. It has been specifically trained to understand Python function structures and best practices. | |
| ### Training Procedure | |
| - **Preprocessing:** The training data underwent standard preprocessing steps, such as tokenization and cleaning, to ensure quality input for fine-tuning. | |
| - **Speeds, Sizes, Times:** More detailed information on training speed and times is needed for transparency. | |
| --- | |
| ## Evaluation | |
| ### Testing Data, Factors & Metrics | |
| #### Testing Data | |
| The testing data consists of Python code from a variety of open-source repositories and function-oriented tasks. | |
| #### Factors | |
| - **Task Complexity:** Evaluation includes both simple function generation and more complex refactoring tasks. | |
| - **Code Quality:** Assessed based on the application of Pythonic principles like readability, clarity, and efficiency. | |
| #### Metrics | |
| - **Accuracy:** Measures the correctness of the generated code. | |
| - **Code Quality:** Evaluates how well the generated code follows Pythonic best practices. | |
| --- | |
| ## Results | |
| More information on the evaluation results is needed to fully assess the model’s performance. | |
| --- | |
| ## Model Examination | |
| A detailed examination of the model's behavior, including edge cases, is needed to identify areas of improvement. | |
| --- | |
| ## Environmental Impact | |
| - **Hardware Type:** More information needed | |
| - **Cloud Provider:** More information needed | |
| - **Carbon Emitted:** More information needed | |
| --- | |
| ## Technical Specifications [Optional] | |
| ### Model Architecture and Objective | |
| The architecture is based on the Transformer model, optimized for code generation tasks. | |
| ### Compute Infrastructure | |
| More details about the compute resources used in training and deployment are needed. | |
| #### Hardware | |
| More information needed. | |
| #### Software | |
| More information needed. | |
| --- | |
| ## Citation | |
| **BibTeX:** | |
| More information needed. | |
| **APA:** | |
| More information needed. | |
| --- | |
| ## Glossary [Optional] | |
| More information needed. | |
| --- | |
| ## More Information [Optional] | |
| More information needed. | |
| --- | |
| ## Model Card Authors [Optional] | |
| S de Jager | |
| --- | |
| ## Model Card Contact | |
| More information needed. | |
| --- | |
| ## How to Get Started with the Model | |
| To get started, use the code below to load and use the PyCodeT5 model. | |
| <details> | |
| <summary> Click to expand </summary> | |
| ```python | |
| from transformers import AutoModelForCausalLM, AutoTokenizer | |
| # Load the model and tokenizer | |
| model_name = 'Salesforce/CodeT5-Python-functions' | |
| model = AutoModelForCausalLM.from_pretrained(model_name) | |
| tokenizer = AutoTokenizer.from_pretrained(model_name) | |
| # Example input | |
| input_text = "def sum(a, b):" | |
| inputs = tokenizer(input_text, return_tensors="pt") | |
| # Generate code | |
| outputs = model.generate(**inputs) | |
| generated_code = tokenizer.decode(outputs[0], skip_special_tokens=True) | |
| print(generated_code) | |
| ``` | |
| </details> | |
| --- |