Skip to content

Commit 0cc61dd

Browse files
committed
Adding ApiEngine and engine_client
1 parent 0871a7a commit 0cc61dd

15 files changed

Lines changed: 751 additions & 502 deletions

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@
2626
>
2727
> These improvements make the `BaseTrainer` class more robust, easier to understand, and more maintainable. > The abstract methods `train` and `eval` still need to be implemented in subclasses to provide the specific > training and evaluation logic for different model types.
2828
29-
- Overall improvement in `OrpoTrainer`, `DPOTrainer`, `CLMTrainer`, `SFTTrainer`.
29+
- Overall improvement in `OrpoTrainer`, `DPOTrainer`, `CLMTrainer`, `SFTTrainer`.
30+
- `ApiEngine` and `engine_client` are added.

README.md

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ With its comprehensive set of features and tools, EasyDeL aims to streamline and
4444
of machine learning models, particularly in the domain of large language models and video-related applications.
4545

4646
### Latest News 🔥
47+
- `ApiEngine` and `engine_client`'s are Added.
4748
- `SFT`, `DPO`, `ORPO`, `CLM` Trainers improvement.
4849
- Gemma2 Is now available.
4950
- StableLM and DBrX model bugs are fixed.
@@ -148,9 +149,79 @@ input_text = "The quick brown fox jumps over the "
148149
The `GenerationPipeline` offers a user-friendly interface to harness the power of EasyDeL's language models for a wide
149150
range of text generation applications.
150151
152+
### ApiEngine A ServeEngine with what you need!
153+
154+
```python
155+
import easydel as ed
156+
from transformers import AutoTokenizer
157+
from jax import numpy as jnp
158+
159+
# Load your pre-trained model and tokenizer
160+
model, params = ed.AutoEasyDeLModelForCausalLM.from_pretrained(...)
161+
tokenizer = AutoTokenizer.from_pretrained(...)
162+
tokenizer.padding_side = "left"
163+
tokenizer.truncation_side = "left"
164+
165+
# Create a GenerationPipeline
166+
pipeline = ed.ChatPipeline(
167+
pipeline=ed.GenerationPipeline(
168+
model=model,
169+
params=params,
170+
tokenizer=tokenizer,
171+
generation_config=ed.GenerationPipelineConfig(
172+
max_new_tokens=256,
173+
temperature=0.4,
174+
),
175+
),
176+
max_prefill_length=2048,
177+
)
178+
engine = ed.ApiEngine(
179+
pipeline=pipeline,
180+
hostname="0.0.0.0",
181+
port=11550
182+
)
183+
engine.fire()
184+
```
185+
186+
Output:
187+
```shell
188+
2024-07-04 18:22:50,707 INFO [easydel.inference.serve_engine.serve] HTTP server started on http://0.0.0.0:11550
189+
2024-07-04 18:22:50,707 INFO [easydel.inference.serve_engine.serve] WebSocket server started on ws://0.0.0.0:11551
190+
2024-07-04 18:22:50,707 INFO [easydel.inference.serve_engine.serve] Gradio server started on http://0.0.0.0:11552
191+
```
192+
193+
#### Run and use With client
194+
195+
```python
196+
from easydel import engine_client
197+
198+
def main():
199+
print("Gradio " + "*" * 50)
200+
for response in engine_client.generate_gradio(
201+
"http://127.0.0.1:11552/",
202+
conversation=[{"content": "hi", "role": "user"}],
203+
):
204+
print(response.sequence_stream, end="")
205+
print()
206+
print(f"{response.tokens_per_second=}")
207+
print(f"{response.elapsed_time=}")
208+
209+
print("WebSocket " + "*" * 50)
210+
for response in engine_client.generate_websocket(
211+
"127.0.0.1:11551",
212+
conversation=[{"content": "hi", "role": "user"}],
213+
):
214+
print(response.response, end="")
215+
print()
216+
print(response.progress)
217+
218+
219+
if __name__ == "__main__":
220+
main()
221+
```
151222
152223
> [!NOTE]
153-
> you can use `EasyDeLServeEngine` which is a Serve API Engine for production purpose sice that's more stable provide
224+
> you can use `ApiEngine` which is a Serve API Engine for production purpose sice that's more stable provide
154225
> versioned
155226
> API and efficient.
156227

python_test/easy_causal_language_model_trainer_test.py

Lines changed: 0 additions & 145 deletions
This file was deleted.

python_test/easy_falcon_clm_trainer_test.py

Lines changed: 0 additions & 114 deletions
This file was deleted.

0 commit comments

Comments
 (0)