Skip to content

Commit

Permalink
FEAT: prototype (xorbitsai#3)
Browse files Browse the repository at this point in the history
* Fix pre-commit

* FEAT: prototype

* Remove xorbits related items from .gitignore
  • Loading branch information
UranusSeven authored Jun 19, 2023
1 parent 52b25a7 commit 74827ce
Show file tree
Hide file tree
Showing 15 changed files with 664 additions and 2 deletions.
144 changes: 144 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
generated/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# IDEs
.idea
.vscode
*.iml

# web staff
node_modules/
static/

# doc
doc/source/savefig/

asv/results

.DS_Store
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
files: python/plexar
files: plexar
repos:
- repo: https://github.com/psf/black
rev: 23.1.0
Expand Down
27 changes: 26 additions & 1 deletion plexar/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
# Copyright 2022-2023 XProbe Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


from . import _version
__version__ = _version.get_versions()['version']

__version__ = _version.get_versions()["version"]


def install():
from .model import install as install_model

install_model()


install()
del install
15 changes: 15 additions & 0 deletions plexar/actor/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2022-2023 XProbe Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from .model import ModelActor
15 changes: 15 additions & 0 deletions plexar/actor/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2022-2023 XProbe Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# TODO: add an API actor running along with the model actor.
15 changes: 15 additions & 0 deletions plexar/actor/gradio.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2022-2023 XProbe Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# TODO: add a gradio actor running on the controller.
29 changes: 29 additions & 0 deletions plexar/actor/model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2022-2023 XProbe Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import xoscar as xo

from ..model.llm.core import Model


class ModelActor(xo.Actor):
def __init__(self, model: Model):
super().__init__()
self._model = model

async def __post_create__(self):
self._model.load()

def __getattr__(self, item):
return getattr(self._model, item)
20 changes: 20 additions & 0 deletions plexar/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2022-2023 XProbe Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
from pathlib import Path

PLEXAR_HOME = str(Path.home() / ".plexar")
PLEXAR_CACHE_DIR = os.path.join(PLEXAR_HOME, "cache")
PLEXAR_LOG_DIR = os.path.join(PLEXAR_HOME, "logs")
13 changes: 13 additions & 0 deletions plexar/deploy/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2022-2023 XProbe Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
71 changes: 71 additions & 0 deletions plexar/deploy/cmdline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Copyright 2022-2023 XProbe Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import click

from plexar.actor import ModelActor

from .. import __version__


@click.group(name="plexar")
@click.version_option(__version__, "--version", "-v")
def cli():
pass


@cli.group()
def model():
pass


@model.command("list")
def model_list():
raise NotImplemented


@model.command("launch")
@click.option("--path", "-p")
def model_launch(path):
import asyncio
import textwrap

import xoscar as xo

from plexar.model.llm.vicuna import VicunaUncensoredGgml

async def _run():
await xo.create_actor_pool(address="localhost:9999", n_process=1)

vu = VicunaUncensoredGgml(model_path=path, llamacpp_model_config={})
vu_ref = await xo.create_actor(
ModelActor, address="localhost:9999", uid="vu", model=vu
)

while True:
i = input("User:\n")
if i == "exit":
break

completion = await vu_ref.chat(i)
text = "\n".join(textwrap.wrap(completion["text"], width=80))
print(f"Assistant:\n{text}")

loop = asyncio.get_event_loop()
loop.run_until_complete(_run())
loop.close()


if __name__ == "__main__":
cli()
Loading

0 comments on commit 74827ce

Please sign in to comment.