Skip to content

armgit / txtai

Public Imported from GitHub
0

💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows

Add examples to documentation

davidmezzettib35f5c7121e0
diff --git a/docs/faq.md b/docs/faq.md
index 741cdac1..d033cf15 100644
--- a/docs/faq.md
+++ b/docs/faq.md
@@ -16,14 +16,58 @@ __Answer__
See the [model guide](../models).
+----------
+
__Question__
-How do you add a progress bar to `embeddings.index`?
+What is the best way to track the progress of an `embeddings.index` call?
__Answer__
Wrap the list or generator passed to the index call with tqdm. See [#478](https://github.com/neuml/txtai/issues/478) for more.
+----------
+
+__Question__
+
+How can models be externally loaded and passed to embeddings and pipelines?
+
+__Answer__
+
+Embeddings example.
+
+```python
+from transformers import AutoModel, AutoTokenizer
+from txtai.embeddings import Embeddings
+
+# Load model externally
+model = AutoModel.from_pretrained("sentence-transformers/all-MiniLM-L6-v2")
+tokenizer = AutoTokenizer.from_pretrained("sentence-transformers/all-MiniLM-L6-v2")
+
+# Pass to embeddings instance
+embeddings = Embeddings({"path": model, "tokenizer": tokenizer})
+```
+
+LLM pipeline example.
+
+```python
+import torch
+
+from transformers import AutoModelForCausalLM, AutoTokenizer
+from txtai.pipeline import LLM
+
+# Load Falcon-7B-Instruct
+path = "tiiuae/falcon-7b-instruct"
+model = AutoModelForCausalLM.from_pretrained(
+ path,
+ torch_dtype=torch.bfloat16,
+ trust_remote_code=True
+)
+tokenizer = AutoTokenizer.from_pretrained(path)
+
+llm = LLM((model, tokenizer))
+```
+
## Common issues
----------
diff --git a/docs/pipeline/text/llm.md b/docs/pipeline/text/llm.md
index 8c67526d..06b05fb6 100644
--- a/docs/pipeline/text/llm.md
+++ b/docs/pipeline/text/llm.md
@@ -46,13 +46,14 @@ llm = LLM("openlm-research/open_llama_3b", task="language-generation")
generator = Generator("openlm-research/open_llama_3b")
```
-As with other pipelines, models can be externally loaded and passed to pipelines. This is useful for models that are not yet supported by Transformers.
+Models can be externally loaded and passed to pipelines. This is useful for models that are not yet supported by Transformers and/or need special initialization.
```python
-from transformers import AutoModelForCausalLM, AutoTokenizer
-
import torch
+from transformers import AutoModelForCausalLM, AutoTokenizer
+from txtai.pipeline import LLM
+
# Load Falcon-7B-Instruct
path = "tiiuae/falcon-7b-instruct"
model = AutoModelForCausalLM.from_pretrained(
@@ -89,6 +90,15 @@ workflow:
- action: llm
```
+Similar to the Python example above, the underlying [Hugging Face pipeline parameters](https://huggingface.co/docs/transformers/main/main_classes/pipelines#transformers.pipeline.model) and [model parameters](https://huggingface.co/docs/transformers/model_doc/auto#transformers.AutoModel.from_pretrained) can be set in pipeline configuration.
+
+```yaml
+llm:
+ path: tiiuae/falcon-7b-instruct
+ torch_dtype: torch.bfloat16
+ trust_remote_code: True
+```
+
### Run with Workflows
```python