Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ctransformers library #933

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/hub/_toctree.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
title: AllenNLP
- local: asteroid
title: Asteroid
- local: ctransformers
title: CTransformers
- local: espnet
title: ESPnet
- local: fastai
Expand Down
40 changes: 40 additions & 0 deletions docs/hub/ctransformers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Using `ctransformers` at Hugging Face

`ctransformers` is a library that provides Python bindings for the Transformer models implemented in C/C++ using GGML library. It supports several state-of-the-art language [models](https://github.com/marella/ctransformers#supported-models).

## Exploring `ctransformers` in the Hub

You can find `ctransformers` models by filtering at the left of the [models page](https://huggingface.co/models?library=ctransformers&sort=downloads).

## Installation

```sh
pip install ctransformers
```

## Using existing models

Load model directly:

```py
from ctransformers import AutoModelForCausalLM, AutoTokenizer

model = AutoModelForCausalLM.from_pretrained("marella/gpt-2-ggml", hf=True)
tokenizer = AutoTokenizer.from_pretrained(model)
```

Use a pipeline as a high-level helper:

```py
from transformers import pipeline

pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
```

[Run in Google Colab](https://colab.research.google.com/drive/1FVSLfTJ2iBbQ1oU2Rqz0MkpJbaB_5Got)

If you want to see how to load a specific model, you can click `Use in CTransformers` and you will be given a working snippet that you can load it!

## Additional resources

- CTransformers [library](https://github.com/marella/ctransformers).
1 change: 1 addition & 0 deletions docs/hub/models-libraries.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ The table below summarizes the supported libraries and their level of integratio
| [AllenNLP](https://github.com/allenai/allennlp) | An open-source NLP research library, built on PyTorch. | ✅ | ✅ | ✅ | ❌ |
| [Asteroid](https://github.com/asteroid-team/asteroid) | Pytorch-based audio source separation toolkit | ✅ | ✅ | ✅ | ❌ |
| [BERTopic](https://github.com/MaartenGr/BERTopic) | BERTopic is a topic modeling library for text and images | ✅ | ✅ | ✅ | ✅ |
| [CTransformers](https://github.com/marella/ctransformers) | Python bindings for the Transformer models implemented in C/C++ using GGML library | ❌ | ❌ | ✅ | ❌ |
| [docTR](https://github.com/mindee/doctr) | Models and datasets for OCR-related tasks in PyTorch & TensorFlow | ✅ | ✅ | ✅ | ❌ |
| [ESPnet](https://github.com/espnet/espnet) | End-to-end speech processing toolkit (e.g. TTS) | ✅ | ✅ | ✅ | ❌ |
| [fastai](https://github.com/fastai/fastai) | Library to train fast and accurate models with state-of-the-art outputs. | ✅ | ✅ | ✅ | ✅ |
Expand Down
21 changes: 20 additions & 1 deletion js/src/lib/interfaces/Libraries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export enum ModelLibrary {
"allennlp" = "allenNLP",
"asteroid" = "Asteroid",
"bertopic" = "BERTopic",
"ctransformers" = "CTransformers",
"diffusers" = "Diffusers",
"doctr" = "docTR",
"espnet" = "ESPnet",
Expand Down Expand Up @@ -122,6 +123,19 @@ const bertopic = (model: ModelData) =>

model = BERTopic.load("${model.id}")`];

const ctransformers = (model: ModelData) =>
[
`# Load model directly
from ctransformers import AutoModelForCausalLM, AutoTokenizer

model = AutoModelForCausalLM.from_pretrained("${model.id}", hf=True)
tokenizer = AutoTokenizer.from_pretrained(model)`,
`# Use a pipeline as a high-level helper
from transformers import pipeline

pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)`,
];

const diffusers_default = (model: ModelData) =>
[`from diffusers import DiffusionPipeline

Expand Down Expand Up @@ -577,6 +591,12 @@ export const MODEL_LIBRARIES_UI_ELEMENTS: Partial<Record<ModelLibraryKey, Librar
repoUrl: "https://github.com/MaartenGr/BERTopic",
snippets: bertopic,
},
"ctransformers": {
btnLabel: "CTransformers",
repoName: "ctransformers",
repoUrl: "https://github.com/marella/ctransformers",
snippets: ctransformers,
},
"diffusers": {
btnLabel: "Diffusers",
repoName: "🤗/diffusers",
Expand Down Expand Up @@ -734,4 +754,3 @@ export const MODEL_LIBRARIES_UI_ELEMENTS: Partial<Record<ModelLibraryKey, Librar
snippets: pythae,
},
} as const;

2 changes: 1 addition & 1 deletion tasks/src/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const TASKS_MODEL_LIBRARIES: Record<PipelineType, ModelLibraryKey[]> = {
"tabular-regression": ["sklearn"],
"tabular-to-text": ["transformers"],
"text-classification": ["adapter-transformers", "spacy", "transformers", "transformers.js"],
"text-generation": ["transformers", "transformers.js"],
"text-generation": ["ctransformers", "transformers", "transformers.js"],
"text-retrieval": [],
"text-to-image": [],
"text-to-speech": ["espnet", "tensorflowtts"],
Expand Down