├── .github
├── CODEOWNERS
├── ISSUE_TEMPLATE
│ ├── bug_report.md
│ └── feature_request.md
├── labeler.yml
├── pull_request_template.md
└── workflows
│ ├── labeler.yml
│ ├── latest-changes.yml.off
│ ├── main.yml
│ ├── mkdocs_ci.yml.off
│ ├── publish-to-pypi.yml
│ ├── stale.yml
│ └── welcome.yml
├── .gitignore
├── .pre-commit-config.yaml
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── LICENSE
├── MANIFEST.in
├── Makefile
├── README.md
├── assets
├── chatbot-demo.mp4
├── llama-inference-api-min.png
├── llm-inference-llama2_chatbot.png
└── llm-inference-min.png
├── docs
├── CHANGELOG.md
├── CNAME
├── index.md
├── overrides
│ └── main.html
└── requirements.txt
├── examples
├── chatbot
│ ├── README.md
│ ├── chatbot-tutorial.ipynb
│ ├── chatbot.ipynb
│ ├── discord_bot.py
│ ├── gradio_demo.py
│ └── llama_bot_ui.py
└── inference-demo.ipynb
├── mkdocs.yml
├── pyproject.toml
├── requirements
├── dev.txt
└── requirements.txt
├── setup.cfg
├── setup.py
├── src
├── llm_chain
│ ├── __init__.py
│ ├── conversation_chain.py
│ ├── llm.py
│ ├── templates.py
│ └── ui
│ │ ├── __init__.py
│ │ └── main.py
└── llm_inference
│ ├── __init__.py
│ ├── download.py
│ ├── model.py
│ ├── serve.py
│ └── token_manipulation.py
└── tests
├── __init__.py
├── __main__.py
└── llm_chain
└── test_chain.py
/.github/CODEOWNERS:
--------------------------------------------------------------------------------
1 | # Lines starting with '#' are comments.
2 | # Each line is a file pattern followed by one or more owners.
3 |
4 | # More details are here: https://help.github.com/articles/about-codeowners/
5 |
6 | # The '*' pattern is global owners.
7 |
8 | # Order is important. The last matching pattern has the most precedence.
9 | # The folders are ordered as follows:
10 |
11 | # In each subsection folders are ordered first by depth, then alphabetically.
12 | # This should make it easy to add new rules without breaking existing ones.
13 |
14 | # Global rule:
15 | * @aniketmaurya
16 |
17 | # tests
18 | /tests/** @aniketmaurya
19 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: 🐛 Bug report
3 | about: Create a report to help us improve
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 |
11 | #### Bug description
12 |
13 |
14 | #### Expected result
15 |
16 |
17 | #### Actual result
18 |
19 |
20 | #### Steps to reproduce
21 |
22 |
23 | 1.
24 | 2.
25 | 3.
26 | #### Context
27 |
28 |
29 |
30 | #### Your Environment
31 |
32 |
33 | * Version used:
34 | * Operating System and version:
35 | * Link to your fork:
36 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: 🚀 Feature request
3 | about: Suggest an idea for this project
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | #### Is your feature request related to a problem? Please describe.
11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12 |
13 | #### Describe the solution you'd like
14 | A clear and concise description of what you want to happen.
15 |
16 | #### Describe alternatives you've considered
17 | A clear and concise description of any alternative solutions or features you've considered.
18 |
19 | #### Additional context
20 | Add any other context or screenshots about the feature request here.
21 |
--------------------------------------------------------------------------------
/.github/labeler.yml:
--------------------------------------------------------------------------------
1 | # Add 'docs' to any changes within 'docs' folder or any subfolders
2 | documentation:
3 | - docs/**/*
4 |
5 | example:
6 | - examples/**/*
7 |
8 | test:
9 | - tests/**/*
10 |
11 | CI:
12 | - .github/**/*
13 | - "*.yaml"
14 | - "*.yml"
15 |
--------------------------------------------------------------------------------
/.github/pull_request_template.md:
--------------------------------------------------------------------------------
1 | #### Changes
2 |
3 |
4 |
5 |
6 | Fixes # (issue)
7 |
8 |
9 | #### Type of change
10 |
11 | - [ ] 📚 Documentation Update
12 | - [ ] 🧪 Tests Cases
13 | - [ ] 🐞 Bug fix (non-breaking change which fixes an issue)
14 | - [ ] 🔬 New feature (non-breaking change which adds functionality)
15 | - [ ] 🚨 Breaking change (fix or feature that would cause existing functionality to not work as expected)
16 | - [ ] 📝 This change requires a documentation update
17 |
18 |
19 | #### Checklist
20 |
21 | - [ ] My code follows the style guidelines of this project
22 | - [ ] I have performed a self-review of my own code
23 | - [ ] I have commented my code, particularly in hard-to-understand areas
24 | - [ ] I have made corresponding changes to the documentation
25 | - [ ] My changes generate no new warnings
26 | - [ ] Did you update CHANGELOG in case of a major change?
27 |
--------------------------------------------------------------------------------
/.github/workflows/labeler.yml:
--------------------------------------------------------------------------------
1 | name: "Pull Request Labeler"
2 | on:
3 | - pull_request_target
4 |
5 | jobs:
6 | triage:
7 | runs-on: ubuntu-latest
8 | steps:
9 | - uses: actions/labeler@v4
10 | with:
11 | repo-token: "${{ secrets.GITHUB_TOKEN }}"
12 |
--------------------------------------------------------------------------------
/.github/workflows/latest-changes.yml.off:
--------------------------------------------------------------------------------
1 | name: Latest Changes
2 |
3 | on:
4 | pull_request_target:
5 | branches:
6 | - main
7 | types:
8 | - closed
9 | # For manually triggering it
10 | workflow_dispatch:
11 | inputs:
12 | number:
13 | description: PR number
14 | required: true
15 |
16 | jobs:
17 | latest-changes:
18 | runs-on: ubuntu-latest
19 | steps:
20 | - uses: actions/checkout@v2
21 | with:
22 | token: ${{ secrets.ACTIONS_TOKEN }}
23 | - uses: docker://tiangolo/latest-changes:0.0.3
24 | with:
25 | token: ${{ secrets.GITHUB_TOKEN }}
26 | latest_changes_file: docs/CHANGELOG.md
27 | latest_changes_header: '## 0.0.3\n'
28 | debug_logs: true
29 |
--------------------------------------------------------------------------------
/.github/workflows/main.yml:
--------------------------------------------------------------------------------
1 | name: pytest
2 | on:
3 | push:
4 | branches: [ main ]
5 | pull_request:
6 | branches: [ main ]
7 |
8 |
9 | jobs:
10 | pytest:
11 | runs-on: ${{ matrix.os }}
12 | strategy:
13 | matrix:
14 | os: [ ubuntu-latest, macos-latest ]
15 | python-version: [3.8, 3.9, "3.10"]
16 | include:
17 | - os: ubuntu-latest
18 | path: ~/.cache/pip
19 | - os: macos-latest
20 | path: ~/Library/Caches/pip
21 | env:
22 | OS: ${{ matrix.os }}
23 | PYTHON: '3.10'
24 |
25 |
26 | steps:
27 | - uses: actions/checkout@v2
28 | with:
29 | fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
30 |
31 | - name: Set up Python ${{ matrix.python-version }}
32 | uses: actions/setup-python@v2
33 | with:
34 | python-version: ${{ matrix.python-version }}
35 |
36 | - name: Cache pip
37 | uses: actions/cache@v2
38 | with:
39 | path: ${{ matrix.path }}
40 | key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
41 | restore-keys: |
42 | ${{ runner.os }}-pip-
43 | ${{ runner.os }}-
44 |
45 | - name: Install dependencies
46 | env:
47 | TORCH_URL: https://download.pytorch.org/whl/cpu/torch_stable.html
48 | run: |
49 | python --version
50 | pip --version
51 | python -m pip install --upgrade pip coverage pytest
52 | pip install --index-url https://download.pytorch.org/whl/nightly/cpu --pre 'torch>=2.1.0dev'
53 | pip install lit_gpt@git+https://github.com/aniketmaurya/install-lit-gpt.git@install
54 | pip install . --quiet
55 | pip list
56 | shell: bash
57 |
58 | - name: Prepare Test
59 | run: |
60 | python tests # download test data
61 |
62 | - name: Run Test with Coverage
63 | run: |
64 | coverage erase
65 | coverage run -m pytest
66 |
67 | - name: Generate Coverage Report
68 | run: |
69 | coverage report -m -i
70 | coverage xml -i
71 |
72 | - name: Upload Coverage to Codecov
73 | if: runner.os != 'macOS'
74 | uses: codecov/codecov-action@v1
75 | with:
76 | token: ${{ secrets.CODECOV_TOKEN }}
77 | file: ./coverage.xml
78 | flags: unittests
79 | env_vars: OS,PYTHON
80 | name: codecov-umbrella
81 | fail_ci_if_error: false
82 |
--------------------------------------------------------------------------------
/.github/workflows/mkdocs_ci.yml.off:
--------------------------------------------------------------------------------
1 | name: MkDocs
2 | on:
3 | push:
4 | branches:
5 | - master
6 | - main
7 | jobs:
8 | deploy:
9 | runs-on: ubuntu-latest
10 | steps:
11 | - uses: actions/checkout@v2
12 | - uses: actions/setup-python@v2
13 | with:
14 | python-version: 3.x
15 | - run: pip install -r docs/requirements.txt
16 | - run: mkdocs gh-deploy --force
17 |
--------------------------------------------------------------------------------
/.github/workflows/publish-to-pypi.yml:
--------------------------------------------------------------------------------
1 | name: Publish Python 🐍 distributions 📦 to PyPI
2 |
3 | on: push
4 |
5 | jobs:
6 | build-n-publish:
7 | name: Build and publish Python 🐍 distributions 📦 to PyPI
8 | runs-on: ubuntu-latest
9 |
10 | steps:
11 | - uses: actions/checkout@master
12 | - name: Set up Python 3.9
13 | uses: actions/setup-python@v1
14 | with:
15 | python-version: 3.9
16 |
17 | - name: Install pypa/build
18 | run: >-
19 | python -m
20 | pip install
21 | build
22 | --user
23 | - name: Build a binary wheel and a source tarball
24 | run: >-
25 | make clean && make build
26 |
27 | - name: Publish distribution 📦 to PyPI
28 | if: startsWith(github.ref, 'refs/tags')
29 | uses: pypa/gh-action-pypi-publish@master
30 | with:
31 | password: ${{ secrets.PYPI_API_TOKEN }}
32 |
--------------------------------------------------------------------------------
/.github/workflows/stale.yml:
--------------------------------------------------------------------------------
1 | name: Mark stale issues and pull requests
2 |
3 | on:
4 | schedule:
5 | - cron: "30 1 * * *"
6 |
7 | jobs:
8 | stale:
9 |
10 | runs-on: ubuntu-latest
11 |
12 | steps:
13 | - uses: actions/stale@v3
14 | with:
15 | repo-token: ${{ secrets.GITHUB_TOKEN }}
16 | stale-issue-message: 'Stale issue message'
17 | stale-pr-message: 'Stale pull request message'
18 | stale-issue-label: 'no-issue-activity'
19 | stale-pr-label: 'no-pr-activity'
20 |
--------------------------------------------------------------------------------
/.github/workflows/welcome.yml:
--------------------------------------------------------------------------------
1 | name: Greet New Contributors
2 |
3 | on: [pull_request_target, issues]
4 |
5 | jobs:
6 | greeting:
7 | runs-on: ubuntu-latest
8 | steps:
9 | - uses: actions/first-interaction@v1
10 | with:
11 | repo-token: ${{ secrets.GITHUB_TOKEN }}
12 | issue-message: "👋 @${{github.actor}}! Thank you for opening your first issue in this repo. We are so happy that you have decided to contribute and value your contribution. Please read these materials before proceeding: [Contributing Guide](https://github.com/gradsflow/gradsflow/blob/master/CONTRIBUTING.md) and [Code of Conduct](https://github.com/gradsflow/gradsflow/blob/master/CODE_OF_CONDUCT.md)."
13 | pr-message: "👋 @${{github.actor}}! Thank you for opening your first pull request in this repo. We are so happy that you have decided to contribute and value your contribution. Please read these materials before proceeding: [Contributing Guide](https://github.com/gradsflow/gradsflow/blob/master/CONTRIBUTING.md) and [Code of Conduct](https://github.com/gradsflow/gradsflow/blob/master/CODE_OF_CONDUCT.md)."
14 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Byte-compiled / optimized / DLL files
2 | __pycache__/
3 | *.py[cod]
4 | *$py.class
5 |
6 | # C extensions
7 | *.so
8 |
9 | # Distribution / packaging
10 | .Python
11 | build/
12 | develop-eggs/
13 | dist/
14 | downloads/
15 | eggs/
16 | .eggs/
17 | lib/
18 | lib64/
19 | parts/
20 | sdist/
21 | var/
22 | wheels/
23 | share/python-wheels/
24 | *.egg-info/
25 | .installed.cfg
26 | *.egg
27 | MANIFEST
28 |
29 | # PyInstaller
30 | # Usually these files are written by a python script from a template
31 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
32 | *.manifest
33 | *.spec
34 |
35 | # Installer logs
36 | pip-log.txt
37 | pip-delete-this-directory.txt
38 |
39 | # Unit test / coverage reports
40 | htmlcov/
41 | .tox/
42 | .nox/
43 | .coverage
44 | .coverage.*
45 | .cache
46 | nosetests.xml
47 | coverage.xml
48 | *.cover
49 | *.py,cover
50 | .hypothesis/
51 | .pytest_cache/
52 | cover/
53 |
54 | # Translations
55 | *.mo
56 | *.pot
57 |
58 | # Django stuff:
59 | *.log
60 | local_settings.py
61 | db.sqlite3
62 | db.sqlite3-journal
63 |
64 | # Flask stuff:
65 | instance/
66 | .webassets-cache
67 |
68 | # Scrapy stuff:
69 | .scrapy
70 |
71 | # Sphinx documentation
72 | docs/_build/
73 |
74 | # PyBuilder
75 | .pybuilder/
76 | target/
77 |
78 | # Jupyter Notebook
79 | .ipynb_checkpoints
80 |
81 | # IPython
82 | profile_default/
83 | ipython_config.py
84 |
85 | # pyenv
86 | # For a library or package, you might want to ignore these files since the code is
87 | # intended to run in multiple environments; otherwise, check them in:
88 | # .python-version
89 |
90 | # pipenv
91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies
93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not
94 | # install all needed dependencies.
95 | #Pipfile.lock
96 |
97 | # poetry
98 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99 | # This is especially recommended for binary packages to ensure reproducibility, and is more
100 | # commonly ignored for libraries.
101 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102 | #poetry.lock
103 |
104 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow
105 | __pypackages__/
106 |
107 | # Celery stuff
108 | celerybeat-schedule
109 | celerybeat.pid
110 |
111 | # SageMath parsed files
112 | *.sage.py
113 |
114 | # Environments
115 | .env
116 | .venv
117 | env/
118 | venv/
119 | ENV/
120 | env.bak/
121 | venv.bak/
122 |
123 | # Spyder project settings
124 | .spyderproject
125 | .spyproject
126 |
127 | # Rope project settings
128 | .ropeproject
129 |
130 | # mkdocs documentation
131 | /site
132 |
133 | # mypy
134 | .mypy_cache/
135 | .dmypy.json
136 | dmypy.json
137 |
138 | # Pyre type checker
139 | .pyre/
140 |
141 | # pytype static type analyzer
142 | .pytype/
143 |
144 | # Cython debug symbols
145 | cython_debug/
146 |
147 | # PyCharm
148 | # JetBrains specific template is maintainted in a separate JetBrains.gitignore that can
149 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
150 | # and can be added to the global gitignore or merged into this file. For a more nuclear
151 | # option (not recommended) you can uncomment the following to ignore the entire idea folder.
152 | #.idea/
153 | *.pth
154 | *.ckpt
155 | *.tokenizer
156 | *.model
157 | .DS_Store
158 | checkpoints/
159 | .vscode/
160 |
--------------------------------------------------------------------------------
/.pre-commit-config.yaml:
--------------------------------------------------------------------------------
1 | # See https://pre-commit.com for more information
2 | # See https://pre-commit.com/hooks.html for more hooks
3 | default_language_version:
4 | python: python3
5 |
6 | ci:
7 | autofix_prs: true
8 | autoupdate_commit_msg: '[pre-commit.ci] pre-commit suggestions'
9 | autoupdate_schedule: quarterly
10 | # submodules: true
11 |
12 | repos:
13 | - repo: https://github.com/pre-commit/pre-commit-hooks
14 | rev: v4.5.0
15 | hooks:
16 | - id: end-of-file-fixer
17 | - id: trailing-whitespace
18 | - id: check-yaml
19 | - id: check-docstring-first
20 | - id: check-toml
21 | - id: check-case-conflict
22 | - id: detect-private-key
23 |
24 | - repo: https://github.com/psf/black
25 | rev: 24.3.0
26 | hooks:
27 | - id: black
28 | name: "Black: The uncompromising Python code formatter"
29 |
30 | - repo: https://github.com/PyCQA/isort
31 | rev: 5.13.2
32 | hooks:
33 | - id: isort
34 | name: "Sort Imports"
35 | args: [ "--profile black" ]
36 |
37 | - repo: https://github.com/codespell-project/codespell
38 | rev: v2.2.6
39 | hooks:
40 | - id: codespell
41 | args:
42 | - --ignore-words-list
43 | - "ans,hist"
44 | - --skip
45 | - "*.bib,*.ipynb"
46 |
47 | - repo: https://github.com/asottile/pyupgrade
48 | rev: v3.15.2
49 | hooks:
50 | - id: pyupgrade
51 | args: [ --py39-plus ]
52 |
53 | - repo: https://github.com/PyCQA/bandit
54 | rev: 1.7.8
55 | hooks:
56 | - id: bandit
57 | language_version: python3
58 | exclude: tests/
59 | args:
60 | - -s
61 | - "B404,B602,B603,B607,B101"
62 |
63 | - repo: https://github.com/kynan/nbstripout
64 | rev: 0.7.1
65 | hooks:
66 | - id: nbstripout
67 | args: [ "max-size 100k" ]
68 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | We as members, contributors, and leaders pledge to make participation in our
6 | community a harassment-free experience for everyone, regardless of age, body
7 | size, visible or invisible disability, ethnicity, sex characteristics, gender
8 | identity and expression, level of experience, education, socio-economic status,
9 | nationality, personal appearance, race, religion, or sexual identity
10 | and orientation.
11 |
12 | We pledge to act and interact in ways that contribute to an open, welcoming,
13 | diverse, inclusive, and healthy community.
14 |
15 | ## Our Standards
16 |
17 | Examples of behavior that contributes to a positive environment for our
18 | community include:
19 |
20 | * Demonstrating empathy and kindness toward other people
21 | * Being respectful of differing opinions, viewpoints, and experiences
22 | * Giving and gracefully accepting constructive feedback
23 | * Accepting responsibility and apologizing to those affected by our mistakes,
24 | and learning from the experience
25 | * Focusing on what is best not just for us as individuals, but for the
26 | overall community
27 |
28 | Examples of unacceptable behavior include:
29 |
30 | * The use of sexualized language or imagery, and sexual attention or
31 | advances of any kind
32 | * Trolling, insulting or derogatory comments, and personal or political attacks
33 | * Public or private harassment
34 | * Publishing others' private information, such as a physical or email
35 | address, without their explicit permission
36 | * Other conduct which could reasonably be considered inappropriate in a
37 | professional setting
38 |
39 | ## Enforcement Responsibilities
40 |
41 | Community leaders are responsible for clarifying and enforcing our standards of
42 | acceptable behavior and will take appropriate and fair corrective action in
43 | response to any behavior that they deem inappropriate, threatening, offensive,
44 | or harmful.
45 |
46 | Community leaders have the right and responsibility to remove, edit, or reject
47 | comments, commits, code, wiki edits, issues, and other contributions that are
48 | not aligned to this Code of Conduct, and will communicate reasons for moderation
49 | decisions when appropriate.
50 |
51 | ## Scope
52 |
53 | This Code of Conduct applies within all community spaces, and also applies when
54 | an individual is officially representing the community in public spaces.
55 | Examples of representing our community include using an official e-mail address,
56 | posting via an official social media account, or acting as an appointed
57 | representative at an online or offline event.
58 |
59 | ## Enforcement
60 |
61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be
62 | reported to the community leaders responsible for enforcement at
63 | hello@domain.com.
64 | All complaints will be reviewed and investigated promptly and fairly.
65 |
66 | All community leaders are obligated to respect the privacy and security of the
67 | reporter of any incident.
68 |
69 | ## Enforcement Guidelines
70 |
71 | Community leaders will follow these Community Impact Guidelines in determining
72 | the consequences for any action they deem in violation of this Code of Conduct:
73 |
74 | ### 1. Correction
75 |
76 | **Community Impact**: Use of inappropriate language or other behavior deemed
77 | unprofessional or unwelcome in the community.
78 |
79 | **Consequence**: A private, written warning from community leaders, providing
80 | clarity around the nature of the violation and an explanation of why the
81 | behavior was inappropriate. A public apology may be requested.
82 |
83 | ### 2. Warning
84 |
85 | **Community Impact**: A violation through a single incident or series
86 | of actions.
87 |
88 | **Consequence**: A warning with consequences for continued behavior. No
89 | interaction with the people involved, including unsolicited interaction with
90 | those enforcing the Code of Conduct, for a specified period of time. This
91 | includes avoiding interactions in community spaces as well as external channels
92 | like social media. Violating these terms may lead to a temporary or
93 | permanent ban.
94 |
95 | ### 3. Temporary Ban
96 |
97 | **Community Impact**: A serious violation of community standards, including
98 | sustained inappropriate behavior.
99 |
100 | **Consequence**: A temporary ban from any sort of interaction or public
101 | communication with the community for a specified period of time. No public or
102 | private interaction with the people involved, including unsolicited interaction
103 | with those enforcing the Code of Conduct, is allowed during this period.
104 | Violating these terms may lead to a permanent ban.
105 |
106 | ### 4. Permanent Ban
107 |
108 | **Community Impact**: Demonstrating a pattern of violation of community
109 | standards, including sustained inappropriate behavior, harassment of an
110 | individual, or aggression toward or disparagement of classes of individuals.
111 |
112 | **Consequence**: A permanent ban from any sort of public interaction within
113 | the community.
114 |
115 | ## Attribution
116 |
117 | This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118 | version 2.0, available at
119 | https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
120 |
121 | Community Impact Guidelines were inspired by [Mozilla's code of conduct
122 | enforcement ladder](https://github.com/mozilla/diversity).
123 |
124 | [homepage]: https://www.contributor-covenant.org
125 |
126 | For answers to common questions about this code of conduct, see the FAQ at
127 | https://www.contributor-covenant.org/faq. Translations are available at
128 | https://www.contributor-covenant.org/translations.
129 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing guidelines
2 |
3 | 👍🎉 First off, thanks for taking the time to contribute! 🎉👍
4 |
5 | The following is a set of guidelines for contributing to Python-Project-Template and its packages, which are hosted in the Python-Project-Template Organization on GitHub. These are mostly guidelines, not rules. Use your best judgment, and feel free to propose changes to this document in a pull request.
6 |
7 | We welcome any kind of contribution to our software, from simple comment or question to a full fledged [pull request](https://help.github.com/articles/about-pull-requests/). Please read and follow our [Code of Conduct](CODE_OF_CONDUCT.md).
8 |
9 | A contribution can be one of the following cases:
10 |
11 | 1. you have a question;
12 | 1. you think you may have found a bug (including unexpected behavior);
13 | 1. you want to make some kind of change to the code base (e.g. to fix a bug, to add a new feature, to update documentation);
14 | 1. you want to make a new release of the code base.
15 |
16 | The sections below outline the steps in each case.
17 |
18 | ## You have a question
19 |
20 | 1. use the search functionality [here](https://github.com/aniketmaurya/python-project-template/issues) to see if someone already filed the same issue;
21 | 2. if your issue search did not yield any relevant results, make a new issue;
22 | 3. apply the "Question" label; apply other labels when relevant.
23 | 4. You can join our Slack group as well.
24 |
25 | ## You think you may have found a bug
26 |
27 | 1. use the search functionality [here](https://github.com/aniketmaurya/python-project-template/issues) to see if someone already filed the same issue;
28 | 1. if your issue search did not yield any relevant results, make a new issue, making sure to provide enough information to the rest of the community to understand the cause and context of the problem. Depending on the issue, you may want to include:
29 | - the [SHA hashcode](https://help.github.com/articles/autolinked-references-and-urls/#commit-shas) of the commit that is causing your problem;
30 | - some identifying information (name and version number) for dependencies you're using;
31 | - information about the operating system;
32 | 1. apply relevant labels to the newly created issue.
33 |
34 | ## You want to make some kind of change to the code base
35 |
36 | 1. (**important**) announce your plan to the rest of the community *before you start working*. This announcement should be in the form of a (new) issue;
37 | 1. (**important**) wait until some kind of consensus is reached about your idea being a good idea;
38 | 1. if needed, fork the repository to your own Github profile and create your own feature branch off of the latest master commit. While working on your feature branch, make sure to stay up to date with the master branch by pulling in changes, possibly from the 'upstream' repository (follow the instructions [here](https://help.github.com/articles/configuring-a-remote-for-a-fork/) and [here](https://help.github.com/articles/syncing-a-fork/));
39 | 1. make sure the existing tests still work by running ``pytest``;
40 | 1. add your own tests (if necessary);
41 | 1. update or expand the documentation;
42 | 1. update the `docs/CHANGELOG.md` file with change;
43 | 1. push your feature branch to (your fork of) the https://github.com/aniketmaurya/python-project-template repository on GitHub;
44 | 1. create the pull request, e.g. following the instructions [here](https://help.github.com/articles/creating-a-pull-request/).
45 |
46 | In case you feel like you've made a valuable contribution, but you don't know how to write or run tests for it, or how to generate the documentation: don't let this discourage you from making the pull request; we can help you! Just go ahead and submit the pull request, but keep in mind that you might be asked to append additional commits to your pull request.
47 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2023 Aniket Maurya
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/MANIFEST.in:
--------------------------------------------------------------------------------
1 | # Manifest syntax https://docs.python.org/2/distutils/sourcedist.html
2 | graft wheelhouse
3 |
4 | recursive-exclude __pycache__ *.py[cod] *.orig
5 |
6 | # Include the README and CHANGELOG
7 | include *.md
8 | recursive-include assets *.png
9 |
10 | exclude app.py
11 | exclude .lightning
12 | exclude .lightningignore
13 |
14 | # Include the license file
15 | include LICENSE
16 |
17 | # Exclude build configs
18 | exclude *.sh
19 | exclude *.toml
20 | exclude *.svg
21 | exclude *.yml
22 | exclude *.yaml
23 |
24 | # exclude tests from package
25 | recursive-exclude tests *
26 | recursive-exclude site *
27 | exclude tests
28 |
29 | # Exclude the documentation files
30 | recursive-exclude docs *
31 | exclude docs
32 |
33 | # Include the Requirements
34 | include requirements/requirements.txt
35 | recursive-include requirements/ *.txt
36 |
37 | # Exclude Makefile
38 | exclude Makefile
39 |
40 | prune .git
41 | prune .github
42 | prune scripts
43 | prune temp*
44 | prune test*
45 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | build-docs:
2 | cp README.md docs/index.md
3 |
4 | docsserve:
5 | mkdocs serve --dirtyreload --livereload
6 |
7 | test:
8 | python tests/__init__.py
9 | pytest
10 |
11 | coverage: ## Run tests with coverage
12 | coverage erase
13 | coverage run -m pytest
14 | coverage report -m
15 | coverage xml
16 |
17 | clean:
18 | rm -rf dist
19 | find . -type f -name "*.DS_Store" -ls -delete
20 | find . | grep -E "(__pycache__|\.pyc|\.pyo)" | xargs rm -rf
21 | find . | grep -E ".pytest_cache" | xargs rm -rf
22 | find . | grep -E ".ipynb_checkpoints" | xargs rm -rf
23 | rm -f .coverage
24 |
25 | style:
26 | black .
27 | isort --profile black .
28 |
29 | push:
30 | git push && git push --tags
31 |
32 | build:
33 | python -m build
34 |
35 | publish-test:
36 | $(style clean build)
37 | twine upload -r testpypi dist/*
38 |
39 | publish-prod:
40 | $(style clean build)
41 | twine upload dist/*
42 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Large Language Model (LLM) Inference API and Chatbot 🦙
2 |
3 | 
4 |
5 | Inference API for LLMs like LLaMA and Falcon powered by Lit-GPT from [Lightning AI](https://lightning.ai)
6 |
7 | ```
8 | pip install llm-inference
9 | ```
10 |
11 | ### Install from main branch
12 | ```bash
13 | pip install git+https://github.com/aniketmaurya/llm-inference.git@main
14 |
15 | # You need to manually install [Lit-GPT](https://github.com/Lightning-AI/lit-gpt) and setup the model weights to use this project.
16 | pip install lit_gpt@git+https://github.com/aniketmaurya/install-lit-gpt.git@install
17 | ```
18 |
19 | ## For Inference
20 |
21 | ```python
22 | from llm_inference import LLMInference, prepare_weights
23 |
24 | path = prepare_weights("EleutherAI/pythia-70m")
25 | model = LLMInference(checkpoint_dir=path)
26 |
27 | print(model("New York is located in"))
28 | ```
29 |
30 |
31 | ## How to use the Chatbot
32 |
33 | 
34 |
35 |
36 | ```python
37 | from llm_chain import LitGPTConversationChain, LitGPTLLM
38 | from llm_inference import prepare_weights
39 |
40 | path = str(prepare_weights("meta-llama/Llama-2-7b-chat-hf"))
41 | llm = LitGPTLLM(checkpoint_dir=path, quantize="bnb.nf4") # 7GB GPU memory
42 | bot = LitGPTConversationChain.from_llm(llm=llm, prompt=llama2_prompt_template)
43 |
44 | print(bot.send("hi, what is the capital of France?"))
45 | ```
46 |
47 | ## Launch Chatbot App
48 |
49 |
52 |
53 | **1. Download weights**
54 | ```py
55 | from llm_inference import prepare_weights
56 | path = prepare_weights("meta-llama/Llama-2-7b-chat-hf")
57 | ```
58 |
59 | **2. Launch Gradio App**
60 |
61 | ```
62 | python examples/chatbot/gradio_demo.py
63 | ```
64 |
--------------------------------------------------------------------------------
/assets/chatbot-demo.mp4:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aniketmaurya/llm-inference/5bb323c4cce70dcbe81cf794aaa0a66b87fe3083/assets/chatbot-demo.mp4
--------------------------------------------------------------------------------
/assets/llama-inference-api-min.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aniketmaurya/llm-inference/5bb323c4cce70dcbe81cf794aaa0a66b87fe3083/assets/llama-inference-api-min.png
--------------------------------------------------------------------------------
/assets/llm-inference-llama2_chatbot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aniketmaurya/llm-inference/5bb323c4cce70dcbe81cf794aaa0a66b87fe3083/assets/llm-inference-llama2_chatbot.png
--------------------------------------------------------------------------------
/assets/llm-inference-min.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aniketmaurya/llm-inference/5bb323c4cce70dcbe81cf794aaa0a66b87fe3083/assets/llm-inference-min.png
--------------------------------------------------------------------------------
/docs/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Release Notes
2 |
3 | ## 0.0.1
4 | * Setup repo
5 |
--------------------------------------------------------------------------------
/docs/CNAME:
--------------------------------------------------------------------------------
1 | CUSTOM_DOMAIN.com
2 |
--------------------------------------------------------------------------------
/docs/index.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aniketmaurya/llm-inference/5bb323c4cce70dcbe81cf794aaa0a66b87fe3083/docs/index.md
--------------------------------------------------------------------------------
/docs/overrides/main.html:
--------------------------------------------------------------------------------
1 | {% extends "base.html" %}
2 |
3 | {% block extrahead %}
4 | {% set title = config.site_name %}
5 | {% if page and page.meta and page.meta.title %}
6 | {% set title = title ~ " - " ~ page.meta.title %}
7 | {% elif page and page.title and not page.is_homepage %}
8 | {% set title = title ~ " - " ~ page.title | striptags %}
9 | {% endif %}
10 |
11 |
12 |