Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Experimental] Add experimental distributed SGD API #2858

Merged
merged 20 commits into from
Sep 20, 2018
86 changes: 86 additions & 0 deletions python/ray/experimental/sgd/chrome_timeline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import ray
import json
import time


class Timeline(object):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove this from this PR.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and run_timeline from sgd.py

def __init__(self, tid):
self.events = []
self.offset = 0
self.start_time = self.time()
self.tid = tid

def patch_ray(self):
orig_log = ray.worker.log

def custom_log(event_type, kind, *args, **kwargs):
orig_log(event_type, kind, *args, **kwargs)
if kind == ray.worker.LOG_SPAN_START:
self.start(event_type)
elif kind == ray.worker.LOG_SPAN_END:
self.end(event_type)
elif kind == ray.worker.LOG_SPAN_POINT:
self.event(event_type)

ray.worker.log = custom_log

def time(self):
return time.time() + self.offset

def reset(self):
self.events = []
self.start_time = self.time()

def start(self, name):
self.events.append((self.tid, "B", name, self.time()))

def end(self, name):
self.events.append((self.tid, "E", name, self.time()))

def event(self, name):
now = self.time()
self.events.append((self.tid, "B", name, now))
self.events.append((self.tid, "E", name, now + .0001))

def merge(self, other):
if other.start_time < self.start_time:
self.start_time = other.start_time
self.events.extend(other.events)
self.events.sort(key=lambda e: e[3])

def chrome_trace_format(self, filename):
out = []
for tid, ph, name, t in self.events:
ts = int((t - self.start_time) * 1000000)
out.append({
"name": name,
"tid": tid,
"pid": tid,
"ph": ph,
"ts": ts,
})
with open(filename, "w") as f:
f.write(json.dumps(out))
print("Wrote chrome timeline to", filename)


if __name__ == "__main__":
a = Timeline(1)
b = Timeline(2)
a.start("hi")
time.sleep(.1)
b.start("bye")
a.start("hi3")
time.sleep(.1)
a.end("hi3")
b.end("bye")
time.sleep(.1)
a.end("hi")
b.start("b1")
b.end("b1")
a.merge(b)
a.chrome_trace_format("test.json")
Loading