You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/source/learners/llm.rst
+150Lines changed: 150 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -135,5 +135,155 @@ The OntoLearner package also offers a streamlined ``LearnerPipeline`` class that
135
135
# Print all returned outputs (include predictions)
136
136
print(outputs)
137
137
138
+
139
+
Custom AutoLLM
140
+
-----------------
141
+
142
+
OntoLearner provides a default ``AutoLLM`` wrapper for handling popular model families (Mistral, Llama, Qwen, etc.) through HuggingFace or external providers. However, in some cases you may want to integrate a model family that is not natively supported (e.g., Falcon, DeepSeek, or a proprietary LLM).
143
+
144
+
For this, you can extend the ``AutoLLM`` class and implement the required
145
+
``load`` and ``generate`` methods. Basic requirements are:
146
+
147
+
1. Inherit from ``AutoLLM``
148
+
2. Implement ``load(model_id)``, if your loging model is different (as an example `mistralai/Mistral-Small-3.2-24B-Instruct-2506 <https://huggingface.co/mistralai/Mistral-Small-3.2-24B-Instruct-2506>`_ uses different type of loading)
149
+
3. Implement ``generate(inputs, max_new_tokens)`` to encodes prompts, performs generation, decodes outputs, and maps them to labels.
150
+
151
+
152
+
.. tab:: Falcon-H
153
+
154
+
The following example shows how to build a Falcon integration:
155
+
156
+
::
157
+
158
+
from ontolearner import AutoLLM
159
+
from typing import List
160
+
import torch
161
+
162
+
class FalconLLM(AutoLLM):
163
+
164
+
def generate(self, inputs: List[str], max_new_tokens: int = 50) -> List[str]:
The following models are specialized within the OntoLearner:
279
+
280
+
- To use `mistralai/Mistral-Small-3.2-24B-Instruct-2506 <https://huggingface.co/mistralai/Mistral-Small-3.2-24B-Instruct-2506>`_ you can use ``MistralLLM`` instead of ``AutoLLM``.
281
+
- To use `Falcon-H` series of LLMs (e.g. `tiiuae/Falcon-H1-1.5B-Deep-Instruct <https://huggingface.co/tiiuae/Falcon-H1-1.5B-Deep-Instruct>`_ you can ``FalconLLM`` instead of ``AutoLLM``.
282
+
283
+
.. note::
284
+
285
+
You can implement as many custom AutoLLM classes as needed (e.g., for proprietary APIs, local models, or new HF releases). As long as they subclass ``AutoLLM`` and implement ``load`` + ``generate``, they will work seamlessly with ``AutoLLMLearner``.
286
+
287
+
138
288
.. hint::
139
289
See `Learning Tasks <https://ontolearner.readthedocs.io/learning_tasks/llms4ol.html>`_ for possible tasks within Learners.
0 commit comments