Spaces:
Running
Running
Adrian Gabriel commited on
Commit ·
1504d65
1
Parent(s): ef0465c
fix layer issue
Browse files- instrumentation.py +11 -6
- static/index.html +22 -3
instrumentation.py
CHANGED
|
@@ -152,7 +152,8 @@ class Instrumentor:
|
|
| 152 |
|
| 153 |
def make_wrapped(orig, name):
|
| 154 |
def wrapped(instance, x, *args, **kwargs):
|
| 155 |
-
#
|
|
|
|
| 156 |
was_inside = instrumentor._inside_layer
|
| 157 |
instrumentor._inside_layer = True
|
| 158 |
try:
|
|
@@ -160,8 +161,10 @@ class Instrumentor:
|
|
| 160 |
finally:
|
| 161 |
instrumentor._inside_layer = was_inside
|
| 162 |
|
| 163 |
-
|
| 164 |
-
|
|
|
|
|
|
|
| 165 |
return result
|
| 166 |
return wrapped
|
| 167 |
|
|
@@ -184,7 +187,7 @@ class Instrumentor:
|
|
| 184 |
|
| 185 |
def make_wrapped(orig, name):
|
| 186 |
def wrapped(instance, predictions, targets, *args, **kwargs):
|
| 187 |
-
#
|
| 188 |
was_inside = instrumentor._inside_layer
|
| 189 |
instrumentor._inside_layer = True
|
| 190 |
try:
|
|
@@ -192,8 +195,10 @@ class Instrumentor:
|
|
| 192 |
finally:
|
| 193 |
instrumentor._inside_layer = was_inside
|
| 194 |
|
| 195 |
-
|
| 196 |
-
|
|
|
|
|
|
|
| 197 |
return result
|
| 198 |
return wrapped
|
| 199 |
|
|
|
|
| 152 |
|
| 153 |
def make_wrapped(orig, name):
|
| 154 |
def wrapped(instance, x, *args, **kwargs):
|
| 155 |
+
# Check if we're already inside a layer to prevent double-tracing
|
| 156 |
+
# (__call__ calls forward, both are wrapped)
|
| 157 |
was_inside = instrumentor._inside_layer
|
| 158 |
instrumentor._inside_layer = True
|
| 159 |
try:
|
|
|
|
| 161 |
finally:
|
| 162 |
instrumentor._inside_layer = was_inside
|
| 163 |
|
| 164 |
+
# Only emit event if this is the outermost call
|
| 165 |
+
if not was_inside:
|
| 166 |
+
meta = {'activation_type': name}
|
| 167 |
+
instrumentor.tracer.op(name.lower(), [x], result, meta)
|
| 168 |
return result
|
| 169 |
return wrapped
|
| 170 |
|
|
|
|
| 187 |
|
| 188 |
def make_wrapped(orig, name):
|
| 189 |
def wrapped(instance, predictions, targets, *args, **kwargs):
|
| 190 |
+
# Check if we're already inside a layer to prevent double-tracing
|
| 191 |
was_inside = instrumentor._inside_layer
|
| 192 |
instrumentor._inside_layer = True
|
| 193 |
try:
|
|
|
|
| 195 |
finally:
|
| 196 |
instrumentor._inside_layer = was_inside
|
| 197 |
|
| 198 |
+
# Only emit event if this is the outermost call
|
| 199 |
+
if not was_inside:
|
| 200 |
+
meta = {'loss_type': name}
|
| 201 |
+
instrumentor.tracer.op(name.lower(), [predictions, targets], result, meta)
|
| 202 |
return result
|
| 203 |
return wrapped
|
| 204 |
|
static/index.html
CHANGED
|
@@ -776,20 +776,39 @@ box("Loss Computation", [y_pred, target_probs, loss], "6")
|
|
| 776 |
|
| 777 |
// Map tensor IDs to group IDs (only unclaimed groups)
|
| 778 |
// Also traces back to include ancestor operations that produced the inputs
|
|
|
|
| 779 |
function getGroupIdsForTensors(tensorIds, includeAncestors = true) {
|
| 780 |
const gids = [];
|
| 781 |
const visited = new Set();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 782 |
|
| 783 |
-
function addGroup(tid) {
|
| 784 |
if (visited.has(tid)) return;
|
| 785 |
visited.add(tid);
|
| 786 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 787 |
const g = groups.find(gr => gr.outputId === tid);
|
| 788 |
if (g && !gids.includes(g.id) && !claimedGroupIds.has(g.id)) {
|
| 789 |
// If includeAncestors, first add groups that produced this group's inputs
|
| 790 |
// This ensures operations are added in execution order (ancestors first)
|
| 791 |
if (includeAncestors && g.inputIds) {
|
| 792 |
-
g.inputIds.forEach(inputId => addGroup(inputId));
|
| 793 |
}
|
| 794 |
|
| 795 |
// Then add this group
|
|
@@ -797,7 +816,7 @@ box("Loss Computation", [y_pred, target_probs, loss], "6")
|
|
| 797 |
}
|
| 798 |
}
|
| 799 |
|
| 800 |
-
tensorIds.forEach(tid => addGroup(tid));
|
| 801 |
return gids;
|
| 802 |
}
|
| 803 |
|
|
|
|
| 776 |
|
| 777 |
// Map tensor IDs to group IDs (only unclaimed groups)
|
| 778 |
// Also traces back to include ancestor operations that produced the inputs
|
| 779 |
+
// but stops at tensors that are explicitly listed in OTHER boxes
|
| 780 |
function getGroupIdsForTensors(tensorIds, includeAncestors = true) {
|
| 781 |
const gids = [];
|
| 782 |
const visited = new Set();
|
| 783 |
+
const tensorIdSet = new Set(tensorIds);
|
| 784 |
+
|
| 785 |
+
// Get all tensor IDs that are explicitly specified in OTHER boxes
|
| 786 |
+
// These act as "boundaries" - we don't trace ancestors past these
|
| 787 |
+
const otherBoxTensorIds = new Set();
|
| 788 |
+
pendingBoxes.forEach(pb => {
|
| 789 |
+
pb.tensorIds.forEach(tid => {
|
| 790 |
+
if (!tensorIdSet.has(tid)) {
|
| 791 |
+
otherBoxTensorIds.add(tid);
|
| 792 |
+
}
|
| 793 |
+
});
|
| 794 |
+
});
|
| 795 |
|
| 796 |
+
function addGroup(tid, isExplicit = false) {
|
| 797 |
if (visited.has(tid)) return;
|
| 798 |
visited.add(tid);
|
| 799 |
|
| 800 |
+
// Don't trace ancestors past tensors that belong to other boxes
|
| 801 |
+
// unless this tensor is explicitly listed in our box
|
| 802 |
+
if (!isExplicit && otherBoxTensorIds.has(tid)) {
|
| 803 |
+
return;
|
| 804 |
+
}
|
| 805 |
+
|
| 806 |
const g = groups.find(gr => gr.outputId === tid);
|
| 807 |
if (g && !gids.includes(g.id) && !claimedGroupIds.has(g.id)) {
|
| 808 |
// If includeAncestors, first add groups that produced this group's inputs
|
| 809 |
// This ensures operations are added in execution order (ancestors first)
|
| 810 |
if (includeAncestors && g.inputIds) {
|
| 811 |
+
g.inputIds.forEach(inputId => addGroup(inputId, false));
|
| 812 |
}
|
| 813 |
|
| 814 |
// Then add this group
|
|
|
|
| 816 |
}
|
| 817 |
}
|
| 818 |
|
| 819 |
+
tensorIds.forEach(tid => addGroup(tid, true));
|
| 820 |
return gids;
|
| 821 |
}
|
| 822 |
|