Repository navigation
0.5.1: conversion routes say what happens; the observer belongs to its context - #14
Merged
Merged
Conversation
StaysInPlace ("stays in place") is the one statement of "same library, same
device: nothing is converted". planned returns it, the run goes through it,
and move_to_device, to_numpy and from_numpy ask it instead of restating it.
DeviceMove applies only when the device differs.
SharedHostBuffer ("shared host buffer") names a host exchange in which the
result is the source's own buffer. Libraries declare it by inheriting
NumpyBufferSharing (NumPy, torch, JAX; TensorFlow copies both ways, measured).
Whether one array was shared is read after the exchange from where the two
arrays begin; a copy is recorded as "host copy" with the declined route named.
to_numpy and from_numpy are conversions through ConversionRoute.run, so the
record is written in one place.
ConversionObserver.current is a ContextVar read through the class: each
thread and asyncio task has its own observer, and a thread run in a copied
context sees the spawner's.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three items reported by the OpenHCS consumer, for the still-unpublished 0.5.1 (details under "Conversion" in
CHANGELOG.md).ConversionObserver.currentis aContextVar: each thread and asyncio task has its own observer; a thread sees the spawner's only when run in a copied context. Tested with two threads interleaving enter/exit.ConversionRoute.plannedand the run share one rule for "nothing is converted": the routeStaysInPlace("stays in place"), which writes no record.planned(lib, dev, lib, dev)is no longerDeviceMove.SharedHostBuffer("shared host buffer"), declared by the library and checked per array by data pointer. Measured on host: NumPy<->torch shares (a negative-stride view copies); JAX->NumPy shares; NumPy->JAX shares only for 64-byte-aligned buffers; TensorFlow copies both ways. When this array could not be shared the record says"host copy"withdeclined_mechanisms=("shared host buffer",).Mechanism names, in trial order:
stays in place,device move,dlpack,shared host buffer,host copy. No name removed.Local: 374 passed on Python 3.10 and 3.13 (NumPy only); 462 passed, 48 skipped on 3.12 with torch, JAX and TensorFlow CPU wheels;
mypy src/ stubs/, ruff, black clean. Not run on a GPU.🤖 Generated with Claude Code