Spaces:
Runtime error
Runtime error
d-matrix
commited on
Update dmx_perplexity.py
Browse filesfixing device mapping for gpt2
- dmx_perplexity.py +3 -9
dmx_perplexity.py
CHANGED
@@ -89,8 +89,9 @@ class DmxPerplexity(evaluate.Metric):
|
|
89 |
max_seq_len = model.config.n_positions
|
90 |
else:
|
91 |
max_seq_len = 2048
|
92 |
-
|
93 |
-
|
|
|
94 |
encodings = tokenizer("\n\n".join(references), return_tensors="pt")
|
95 |
|
96 |
stride = max_seq_len
|
@@ -105,13 +106,6 @@ class DmxPerplexity(evaluate.Metric):
|
|
105 |
target_ids = input_ids.clone()
|
106 |
target_ids[:, :-trg_len] = -100
|
107 |
|
108 |
-
# Setting device for labels if mdodel has device mapping
|
109 |
-
if hasattr(model, "hf_device_map"):
|
110 |
-
last_device = "cuda:" + str(
|
111 |
-
max(model.hf_device_map.values())
|
112 |
-
)
|
113 |
-
target_ids = target_ids.to(last_device)
|
114 |
-
|
115 |
with torch.no_grad():
|
116 |
outputs = model(input_ids, labels=target_ids)
|
117 |
if isinstance(outputs, Dict):
|
|
|
89 |
max_seq_len = model.config.n_positions
|
90 |
else:
|
91 |
max_seq_len = 2048
|
92 |
+
|
93 |
+
if not hasattr(model, "hf_device_map"):
|
94 |
+
model = model.to(device)
|
95 |
encodings = tokenizer("\n\n".join(references), return_tensors="pt")
|
96 |
|
97 |
stride = max_seq_len
|
|
|
106 |
target_ids = input_ids.clone()
|
107 |
target_ids[:, :-trg_len] = -100
|
108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
with torch.no_grad():
|
110 |
outputs = model(input_ids, labels=target_ids)
|
111 |
if isinstance(outputs, Dict):
|