Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
dnth committed Oct 11, 2024
1 parent 80dbce2 commit f18e710
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 46 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
![PyPI version](https://img.shields.io/pypi/v/xinfer.svg?style=for-the-badge&logo=pypi&logoColor=white&label=PyPI&color=blue)
![Downloads](https://img.shields.io/pypi/dm/xinfer.svg?style=for-the-badge&logo=pypi&logoColor=white&label=Downloads&color=purple)
![License](https://img.shields.io/badge/License-Apache%202.0-green.svg?style=for-the-badge&logo=apache&logoColor=white)


Expand Down
6 changes: 4 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Welcome to xinfer


[![image](https://img.shields.io/pypi/v/xinfer.svg)](https://pypi.python.org/pypi/xinfer)
![PyPI version](https://img.shields.io/pypi/v/xinfer.svg?style=for-the-badge&logo=pypi&logoColor=white&label=PyPI&color=blue)
![Downloads](https://img.shields.io/pypi/dm/xinfer.svg?style=for-the-badge&logo=pypi&logoColor=white&label=Downloads&color=purple)
![License](https://img.shields.io/badge/License-Apache%202.0-green.svg?style=for-the-badge&logo=apache&logoColor=white)


**A unified interface to run inference on machine learning libraries.**
**A unified interface to run inference on computer vision libraries.**


- Free software: Apache Software License 2.0
Expand Down
65 changes: 64 additions & 1 deletion docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,69 @@

To use xinfer in a project:

```
```python
import xinfer
```

## Listing Available Models

You can list the available models using the `list_models()` function:

```python
from xinfer import list_models
list_models()
```

This will display a table of available models and their implementations.

```
Available Models
┏━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Implementation ┃ Model Type ┃
┡━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ transformers │ Salesforce/blip2-opt-2.7b │
│ transformers │ sashakunitsyn/vlrm-blip2-opt-2.7b │
└────────────────┴───────────────────────────────────┘
```

## Loading and Using a Model

### BLIP2 Model

Here's an example of how to load and use the BLIP2 model:

```python
from xinfer import get_model

# Instantiate a Transformers model
model = get_model("Salesforce/blip2-opt-2.7b", implementation="transformers")

# Input data
image = "https://example.com/path/to/image.jpg"
prompt = "What's in this image? Answer:"

# Run inference
processed_input = model.preprocess(image, prompt)
prediction = model.predict(processed_input)
output = model.postprocess(prediction)

print(output)
```

You can also customize the generation parameters:

```python
prediction = model.predict(processed_input, max_new_tokens=200)
```

### VLRM-finetuned BLIP2 Model

Similarly, you can use the VLRM-finetuned BLIP2 model:

```python
model = get_model("sashakunitsyn/vlrm-blip2-opt-2.7b", implementation="transformers")

# Use the model in the same way as the BLIP2 model
```

Both models can be used for tasks like image description and visual question answering.
36 changes: 1 addition & 35 deletions docs/xinfer.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,7 @@

# xinfer module

The `xinfer` module provides a flexible and extensible framework for working with various AI models, particularly focusing on vision-language models like BLIP2.

## Main Functions

### list_models

::: xinfer.list_models

This function displays a table of all available models in the ModelRegistry. It uses the Rich library to create a formatted table with two columns: "Implementation" and "Model Type".

### get_model

::: xinfer.get_model

This function retrieves a model instance based on the specified model type and implementation. It returns an instance of a class that inherits from `BaseModel`.

Parameters:
- `model_type` (str): The type of the model to retrieve.
- `implementation` (str): The implementation of the model.
- `**kwargs`: Additional keyword arguments to pass to the model constructor.

Returns:
- An instance of the requested model.

Raises:
- `ValueError`: If the specified implementation or model type is not supported.

## Model Registry

The `ModelRegistry` class manages the registration and retrieval of models. It provides the following class methods:

### register

::: xinfer.ModelRegistry.register

This method registers a model class with the ModelRegistry.



16 changes: 8 additions & 8 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ nav:
- Home: index.md
- Installation: installation.md
- Usage: usage.md
- Contributing: contributing.md
- FAQ: faq.md
- Changelog: changelog.md
- Report Issues: https://github.com/dnth/xinfer/issues
- Examples:
- examples/intro.ipynb
- API Reference:
- xinfer module: xinfer.md
# - Contributing: contributing.md
# - FAQ: faq.md
# - Changelog: changelog.md
# - Report Issues: https://github.com/dnth/xinfer/issues
# - Examples:
# - examples/intro.ipynb
# - API Reference:
# - xinfer module: xinfer.md
# - common module: common.md

0 comments on commit f18e710

Please sign in to comment.