interleaver¶
interleaver
¶
Events
¶
Bases: Enum
Enum for different types of events in the interleaving process.
Cancelation
¶
Bases: Exception
Exception raised when a request is canceled.
EarlyStopException
¶
Bases: Exception
Exception raised to stop the execution of the model.
SkipException
¶
Bases: Exception
Exception raised to skip the execution of the model.
Interleaver
¶
Interleaver(mediators: List[Mediator] = [], tracer: InterleavingTracer = None, batcher: Batcher = None)
Manages the interleaving of model execution and interventions.
This class coordinates the flow between the model's forward pass and user-defined intervention functions, allowing for inspection and modification of intermediate values.
| ATTRIBUTE | DESCRIPTION |
|---|---|
mediators |
A dictionary of mediator names to mediator objects. Each meidator is responsible for a single invoke, or intervention function.
TYPE:
|
tracer |
The tracer object that created this interleaver. Occationaly useful to know the tracer type for this interleaving.
TYPE:
|
batcher |
The batcher object that manages the slice of inputs associtated with each mediator.
TYPE:
|
current |
The current mediator that is being processed. Must be update before resuming a given mediator.
TYPE:
|
| PARAMETER | DESCRIPTION |
|---|---|
mediators
|
A list of mediator objects.
TYPE:
|
tracer
|
The tracer object that created this interleaver.
TYPE:
|
batcher
|
The batcher object that manages the slice of inputs associtated with each mediator.
TYPE:
|
interleaving
property
¶
Check if the interleaver is currently interleaving.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if the interleaver is interleaving, False otherwise
TYPE:
|
initialize
¶
initialize(mediators: List[Mediator], tracer: InterleavingTracer, batcher: Batcher = None)
iterate_provider
¶
Update a provider string to include which iteration of the provider is being provided.
| PARAMETER | DESCRIPTION |
|---|---|
provider
|
The provider string to update
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The updated provider string |
Example
provider = "model.transformer.h[0].input" iterate_provider(provider) "model.transformer.h[0].input.i0"
provider = "model.transformer.h[0].input" iterate_provider(provider) "model.transformer.h[0].input.i1"
provider = "model.transformer.h[0].input" iterate_provider(provider) "model.transformer.h[0].input.i2"
iterate_requester
¶
Update a requester string to include which iteration of the requester is being requested. This is determined by the current mediator's iteration attribute, or influced by .iter contexts.
| PARAMETER | DESCRIPTION |
|---|---|
requester
|
The requester string to update
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The updated requester string |
wrap_module
¶
Instruments a PyTorch module to intercept inputs and outputs for interleaving.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The module to instrument
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None |
wrap_operation
¶
Wrap an operation to intercept inputs and outputs for intervention, as well as the function itself. Used by Envoy.source to hook into intermediate operations of a forward pass.
| PARAMETER | DESCRIPTION |
|---|---|
fn
|
The intermediate operation function to wrap
TYPE:
|
name
|
The fully qualified name of the operation
TYPE:
|
bound_obj
|
The object fn is bound to if it is a method
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Callable
|
A wrapped version of the function |
handle
¶
Handle a provider's value, allowing mediators to consume and modify it.
| PARAMETER | DESCRIPTION |
|---|---|
provider
|
The identifier of the provider
TYPE:
|
value
|
The value being provided
TYPE:
|
iterate
|
Whether to iterate the provider string
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Any
|
The original or modified value |
Mediator
¶
Mediator(intervention: Callable, info: 'Tracer.Info', name: Optional[str] = None, batch_group: Optional[List[int]] = None, stop: Optional[int] = None)
Mediates between the model execution and a single intervention function.
This class handles the communication between the model's forward pass and a user-defined intervention function, allowing for inspection and modification of intermediate values.
| ATTRIBUTE | DESCRIPTION |
|---|---|
interleaver |
The interleaver that this mediator is currently running in
TYPE:
|
intervention |
The intervention function to mediate
TYPE:
|
info |
Information about the tracing context associated with this mediator
TYPE:
|
name |
Optional name for the mediator
TYPE:
|
batch_group |
Optional batch group for the mediator to determine which slice of tensors are being intervened on
TYPE:
|
event_queue |
Where the mediator (worker thread) puts events to be processed by the interleaver (main thread). Will only ever have 1 or 0 items in the queue.
TYPE:
|
response_queue |
Where the interleaver (main thread) puts responses to events, to then be processed by the mediator (worker thread). Will only ever have 1 or 0 items in the queue.
TYPE:
|
worker |
The thread that runs the intervention function
TYPE:
|
history |
A set of providers that have been seen by the mediator. Used to detect out of order interventions.
TYPE:
|
iteration_tracker |
A dictionary tracking the number of times each provider has been seen by the mediator.
TYPE:
|
iteration |
The current iteration this mediator is interventing on
TYPE:
|
user_cache |
A list of caches to be used by the mediator
TYPE:
|
all_stop |
Optional number of times to execute this mediator
TYPE:
|
| PARAMETER | DESCRIPTION |
|---|---|
intervention
|
The intervention function
TYPE:
|
info
|
Information about the tracing context
TYPE:
|
name
|
Optional name for the mediator
TYPE:
|
stop
|
Optional number of times to execute this mediator
TYPE:
|
frame
property
¶
Get the frame of the intervention function.
| RETURNS | DESCRIPTION |
|---|---|
FrameType
|
The frame of the intervention function |
OutOfOrderError
¶
Bases: Exception
Exception raised when interventions are defined out of order.
Value
¶
start
¶
start(interleaver: Interleaver)
Start the mediator's intervention thread.
| PARAMETER | DESCRIPTION |
|---|---|
interleaver
|
The interleaver managing this mediator
TYPE:
|
handle
¶
Process a provider and its value. Depending on which event this mediator is waiting on, it will either: - Respond with the value - Swap (replace) the value with a new value - Respond with an out of order error - Skip the value - Set a barrier - End the execution (cancels the mediator)
| PARAMETER | DESCRIPTION |
|---|---|
provider
|
The identifier of the provider
TYPE:
|
handle_value_event
¶
Handle a value event by providing the requested value or recording a missed provider.
| PARAMETER | DESCRIPTION |
|---|---|
requester
|
The identifier of the requester
TYPE:
|
provider
|
The identifier of the provider
TYPE:
|
Returns: bool: Indicating whether the request was fulfilled by this processor, If so, continue processing events.
handle_swap_event
¶
Handle a swap event by swapping the value if the provider matches the requester.
| PARAMETER | DESCRIPTION |
|---|---|
requester
|
The identifier of the requester
TYPE:
|
provider
|
The identifier of the provider
TYPE:
|
swap_value
|
The value to swap in
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
Indicating whether the swap was fulfilled by this processor, If so, continue processing events. |
handle_exception_event
¶
Handle an exception event by raising the exception.
| PARAMETER | DESCRIPTION |
|---|---|
exception
|
The exception to raise
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
Flag to stop processing events. |
handle_barrier_event
¶
Handle a barrier event by setting a barrier.
respond
¶
Respond from the interleaver (main thread) to the mediator (worker thread) the value for a pending event.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
The value to provide
TYPE:
|
send
¶
send(event: Events, requester: Any)
Send an event to interleaver (main thread) from this mediator (worker thread), and wait for it to be processed by the interleaver.
| PARAMETER | DESCRIPTION |
|---|---|
event
|
The event to send
TYPE:
|
requester
|
The identifier of the requester, plus any additional data for the event.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Any
|
The response from the provider |
request
¶
Request a value from a specific provider.
| PARAMETER | DESCRIPTION |
|---|---|
requester
|
The identifier of the provider to request a value from
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Any
|
The requested value |
swap
¶
Send a swap event to replace the value of a provider.
| PARAMETER | DESCRIPTION |
|---|---|
requester
|
The identifier of the requester
TYPE:
|
value
|
The value to swap in
TYPE:
|
exception
¶
Signal that an exception occurred during intervention.
| PARAMETER | DESCRIPTION |
|---|---|
exception
|
The exception that occurred
TYPE:
|
set_user_cache
¶
Set the user cache for this mediator.
| PARAMETER | DESCRIPTION |
|---|---|
cache
|
The cache to set
TYPE:
|