MCPcopy Create free account
hub / github.com/CSAILVision/gandissect / decode_intervention_array

Function decode_intervention_array

netdissect/serverstate.py:425–439  ·  view source on GitHub ↗
(interventions, layer_shapes)

Source from the content-addressed store, hash-verified

423 bitindex += 1
424
425def decode_intervention_array(interventions, layer_shapes):
426 result = {}
427 for channels in [decode_intervention(intervention, layer_shapes)
428 for intervention in (interventions or [])]:
429 for layer, channel in channels.items():
430 if layer not in result:
431 result[layer] = channel
432 continue
433 accum = result[layer]
434 newalpha = 1 - (1 - channel[:1]) * (1 - accum[:1])
435 newvalue = (accum[1:] * accum[:1] * (1 - channel[:1]) +
436 channel[1:] * channel[:1]) / (newalpha + 1e-40)
437 accum[:1] = newalpha
438 accum[1:] = newvalue
439 return result
440
441def decode_intervention(intervention, layer_shapes):
442 # Every plane of an intervention is a solid choice of activation

Callers 3

generate_imagesMethod · 0.85
get_featuresMethod · 0.85
get_featuremapsMethod · 0.85

Calls 1

decode_interventionFunction · 0.85

Tested by

no test coverage detected