Skip to content

Commit

Permalink
Progress bar for remote steaming result download.
Browse files Browse the repository at this point in the history
  • Loading branch information
JadenFiotto-Kaufman committed Jan 2, 2024
1 parent 4fc320c commit 99d8ba4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
27 changes: 23 additions & 4 deletions src/nnsight/contexts/Runner.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from __future__ import annotations

import io
import pickle

import requests
import socketio
from tqdm import tqdm

from .. import CONFIG, pydantics
from ..logger import logger
Expand Down Expand Up @@ -118,16 +120,33 @@ def blocking_response(data):

# If the status of the response is completed, update the local nodes that the user specified to save.
# Then disconnect and continue.

if response.status == pydantics.ResponseModel.JobStatus.COMPLETED:
result_bytes = io.BytesIO()
result_bytes.seek(0)

with requests.get(
url=f"https://{CONFIG.API.HOST}/retrieve/{response.id}", stream=True
url=f"https://{CONFIG.API.HOST}/result/{response.id}", stream=True
) as stream:
result_response = pydantics.ResponseModel(**pickle.load(stream.raw))
total_size = float(stream.headers["Content-length"])

with tqdm(
total=total_size, unit="B", unit_scale=True
) as progress_bar:
for data in stream.iter_content(chunk_size=4000000):
progress_bar.update(len(data))
result_bytes.write(data)

result_bytes.seek(0)

result = pydantics.ResultModel(**pickle.load(result_bytes))

result_bytes.close()

for name, value in result_response.result.saves.items():
for name, value in result.saves.items():
self.graph.nodes[name].value = value

self.output = result_response.result.output
self.output = result.output

sio.disconnect()
# Or if there was some error.
Expand Down
4 changes: 2 additions & 2 deletions src/nnsight/pydantics/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .Response import ResponseModel
from .Config import ConfigModel
from .Request import RequestModel
from .Config import ConfigModel
from .Response import ResponseModel, ResultModel

0 comments on commit 99d8ba4

Please sign in to comment.