Spaces:
Runtime error
Runtime error
Commit
·
4c16a19
1
Parent(s):
1e25943
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,29 +7,22 @@ from src.client import DistributedBloomForCausalLM
|
|
| 7 |
|
| 8 |
INITIAL_PEERS = ['/ip4/193.106.95.184/tcp/443/p2p/QmSXDXLeSMXjS4YerDrdn1zpGQaNzkZ9ogN2SoAEyAdDhs']
|
| 9 |
|
| 10 |
-
import hivemind
|
| 11 |
dht1 = hivemind.DHT(start=True)
|
| 12 |
dht2 = hivemind.DHT(start=True, initial_peers=dht1.get_visible_maddrs())
|
| 13 |
|
| 14 |
|
| 15 |
tokenizer = transformers.BloomTokenizerFast.from_pretrained("bigscience/test-bloomd-6b3")
|
| 16 |
-
|
| 17 |
|
| 18 |
def inference(text, seq_length=1):
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
#return text[::-1] + '\n' + '\n'.join(os.listdir('.'))
|
| 27 |
-
try:
|
| 28 |
-
dht3 = hivemind.DHT(start=True, initial_peers=INITIAL_PEERS)
|
| 29 |
|
| 30 |
-
assert dht1.store('key', text[::-1], hivemind.get_dht_time() + 999)
|
| 31 |
-
return repr(dht2.get('key'))
|
| 32 |
-
except Exception as e:
|
| 33 |
-
return repr(e)
|
| 34 |
iface = gr.Interface(fn=inference, inputs="text", outputs="text")
|
| 35 |
iface.launch()
|
|
|
|
| 7 |
|
| 8 |
INITIAL_PEERS = ['/ip4/193.106.95.184/tcp/443/p2p/QmSXDXLeSMXjS4YerDrdn1zpGQaNzkZ9ogN2SoAEyAdDhs']
|
| 9 |
|
| 10 |
+
import hivemind # test that DHT instances work on localhost
|
| 11 |
dht1 = hivemind.DHT(start=True)
|
| 12 |
dht2 = hivemind.DHT(start=True, initial_peers=dht1.get_visible_maddrs())
|
| 13 |
|
| 14 |
|
| 15 |
tokenizer = transformers.BloomTokenizerFast.from_pretrained("bigscience/test-bloomd-6b3")
|
| 16 |
+
model = DistributedBloomForCausalLM.from_pretrained("bigscience/test-bloomd-6b3", initial_peers=INITIAL_PEERS, low_cpu_mem_usage=True, torch_dtype=torch.float32)
|
| 17 |
|
| 18 |
def inference(text, seq_length=1):
|
| 19 |
+
input_ids = tokenizer(text, return_tensors='pt')['input_ids']
|
| 20 |
+
with torch.inference_mode(), model.transformer.h.inference_session() as remote_transformer:
|
| 21 |
+
for i in range(seq_length):
|
| 22 |
+
h = model.transformer.word_embeddings(input_ids)
|
| 23 |
+
h = model.transformer.word_embeddings_layernorm(h)
|
| 24 |
+
h = remote_transformer.step(h)
|
| 25 |
+
return repr(h)
|
|
|
|
|
|
|
|
|
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
iface = gr.Interface(fn=inference, inputs="text", outputs="text")
|
| 28 |
iface.launch()
|