d-matrix
commited on
Commit
•
e394a6e
1
Parent(s):
31a5ab8
Update README.md
Browse files
README.md
CHANGED
@@ -49,32 +49,29 @@ Prerequisites:
|
|
49 |
- clone this repo. "cd" to the cloned repo.
|
50 |
```python
|
51 |
>>> import os
|
52 |
-
>>> import torch
|
53 |
>>> from mltools import dmx
|
54 |
-
>>> from transformers import pipeline
|
55 |
>>> import evaluate
|
56 |
>>> from datasets import load_dataset
|
57 |
|
58 |
-
|
59 |
-
>>> my_hf_token = os.environ.get("Dmatrix_HF_Token")
|
60 |
-
>>> device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
61 |
|
62 |
>>> pipe = pipeline(
|
63 |
>>> "text-generation",
|
64 |
>>> model="d-matrix/distilgpt2",
|
65 |
-
>>> device=device,
|
66 |
>>> use_auth_token=my_hf_token,
|
|
|
|
|
|
|
|
|
|
|
67 |
>>> )
|
68 |
-
>>> pipe.model = dmx.Model(pipe.model,monkey_patched=False,hf=True,input_names=["input_ids", "labels"])
|
69 |
|
70 |
-
|
71 |
-
>>> pipe.model.transform('FALLBACK.yaml')
|
72 |
|
73 |
-
# Evaluate
|
74 |
>>> perplexity = evaluate.load("d-matrix/dmx_perplexity", module_type="metric")
|
75 |
>>> input_texts = load_dataset("ptb_text_only", "penn_treebank", split="test")["sentence"]
|
76 |
-
>>> pipe.model.
|
77 |
-
>>> results = perplexity.compute(model=pipe.model.body,references=input_texts)
|
78 |
>>> print(results)
|
79 |
{'loss': 4.164604187011719, 'perplexity': 64.36720275878906}
|
80 |
```
|
|
|
49 |
- clone this repo. "cd" to the cloned repo.
|
50 |
```python
|
51 |
>>> import os
|
|
|
52 |
>>> from mltools import dmx
|
53 |
+
>>> from transformers import pipeline
|
54 |
>>> import evaluate
|
55 |
>>> from datasets import load_dataset
|
56 |
|
57 |
+
>>> my_hf_token = os.environ.get("HUGGING_FACE_HUB_TOKEN")
|
|
|
|
|
58 |
|
59 |
>>> pipe = pipeline(
|
60 |
>>> "text-generation",
|
61 |
>>> model="d-matrix/distilgpt2",
|
|
|
62 |
>>> use_auth_token=my_hf_token,
|
63 |
+
>>> trust_remote_code=True,
|
64 |
+
>>> # device_map="auto", # use this line for enabling pipeline parallel
|
65 |
+
>>> )
|
66 |
+
>>> pipe.model = dmx.Model(
|
67 |
+
>>> pipe.model, monkey_patched=False, hf=True, input_names=["input_ids", "labels"]
|
68 |
>>> )
|
|
|
69 |
|
70 |
+
>>> pipe.model.transform("FALLBACK.yaml")
|
|
|
71 |
|
|
|
72 |
>>> perplexity = evaluate.load("d-matrix/dmx_perplexity", module_type="metric")
|
73 |
>>> input_texts = load_dataset("ptb_text_only", "penn_treebank", split="test")["sentence"]
|
74 |
+
>>> results = perplexity.compute(model=pipe.model.body, references=input_texts)
|
|
|
75 |
>>> print(results)
|
76 |
{'loss': 4.164604187011719, 'perplexity': 64.36720275878906}
|
77 |
```
|