Manuscript Offprint
arXiv:2610.12571An all-transistor physical-learning transformer can be trained to perform in-context learning
Abstract
Most systems trained by equilibrium propagation or coupled learning are in the same class as multi-layer perceptrons: while they may be universal function approximators, they struggle to learn associative tasks which are easy for transformers. Equilibrium propagation relies on a bidirectional flow of information through the physical system between input and output. The reverse flow is broken by more complex nonlinear systems, such as those performing multiplication which is needed to express dot-product attention. Here we explicitly restore this bidirectional flow by introducing extra circuit elements for this purpose into a double or dyadic circuit. We then use these ideas to construct an attention mechanism exploiting the exponential current law of sub-threshold MOSFET devices. We show that in simulations this circuit can be trained to perform a simple in-context learning task, despite using realistic reverse components which transmit only an approximate gradient. For this training to succeed we need cross-entropy loss (not mean squared error). We generate nudges appropriate for this loss using a novel floating circuit element, based on the same MOSFET sub-circuit used for softmax. We train the resistors in this circuit using the Lion optimiser, which can be implemented using one capacitor per parameter to store local memory of past gradient estimates.
1 Introduction
Physical learning is a machine-learning paradigm in which an analogue physical system performs both the forward computation (say from input to classification) and also the back-propagation of an error signal to allow training. In the simplest equilibrium propagation case [1], an electrical circuit supplied with some input voltages settles to a free steady state, and some of the resulting node voltages are the output. During training, the error signal is current injected into the output nodes, causing the system to find a new nudged steady state. At each resistor, the contrast between free and nudged currents allows us to precisely reconstruct the gradient of the loss function with respect to this one conductance, and hence to adjust the resistor so as to perform gradient descent. This scheme works because the circuit's equilibrium states minimise an energy function, namely the power dissipated, subject to boundary conditions at the input and, during training, at the output. Reducing the difference in energy between these two states performs gradient descent.
This simple setup works for systems of reciprocal interactions, including for instance networks of resistors and diodes. Such networks can easily be constructed to mimic a multi-layer perceptron (MLP) with relu nonlinearities, and thus, like MLPs, they are universal function approximators [2]. However, the ability to represent any function does not imply the ability to learn any task. This is why artificial neural networks moved beyond MLPs and related architectures, and are now dominated by transformer architectures [3]. In a transformer, different parts of the input are compared, most naturally implemented with transistors, not resistors. In the simplest cases different inputs, voltages, are eventually multiplied by each other to perform dot-product attention. By contrast, an MLP only multiplies inputs by weights, which is what Ohm's law can implement. An ideal voltage multiplier is a perfect bilinear voltage-controlled current source (VCCS), which is perfectly non-reciprocal, in the sense that it completely blocks error signal from propagating back to earlier circuit elements.
Here, we first explore how to construct modified circuits which allow the physical back-propagation of error signal through arbitrary nonlinear elements. We do this with a double or dyadic circuit based on [4, 5], in which the steady state is in general a saddle point of some dyadic potential, rather than a minimum of energy. Instead of using one circuit for the free case and one for the nudged [6], here the mean of each pair of node voltages is the forward computation, while the difference is the error signal. Extra circuit elements are added to explicitly pass the error signal backwards, when necessary. There is an analogy to how automatic differentiation works on the computer, in which the forward computation is a chain of functions, and the pullback of each function is the appropriate backward operation for the error signal.
And second, we show explicitly one possible architecture with transformer-like behaviour. Rather than precisely implementing the familiar dot-product attention mechanism, we construct here a version which exploits the exponential nonlinearity of MOSFET devices in a natural way, replacing the dot product with a bump circuit [7] analogous to Bahdanau attention [8]. We implement softmax by sharing a fixed tail current among outputs controlled by input gate voltages [9]. While the exact dyadic double of an individual MOSFET is complicated, we show that quite crude approximations to these larger circuit blocks (using other realistic components) still allow the double circuit to learn. The learned parameters are all adjustable resistors, as in the earlier MLP circuits.
Along the way, we show that some other ideas from digital neural networks can be copied to this analogue world. We implement loss functions as floating circuit elements connected to the doubled circuit. Mean squared error is simple, but cross-entropy can also be implemented using the same MOSFET sub-circuits. And we show how to implement local optimisation rules smarter than gradient descent. Adam [10] and Lion [11] store some memory of past updates, always for just one parameter, hence they obey the locality of physical learning.
Finally, to test this model we use a simple in-context learning (ICL) task, whose input is a string of characters [12, 13]. The task, learned from examples, is to take the last character in the input and compare it to all earlier ones, retrieve part of the input near to that match, and return this as the output. This is fundamentally what the learned induction heads in a transformer do [14]. The input characters are encoded as embedding vectors, columns of an input matrix. The input matrices for this task are smaller than those of the classic MNIST learning task, of classifying handwritten digits from pixel images [15]. Yet this ICL task is very difficult for an MLP to learn, so it serves as a test that the model truly has new capabilities.
Physical learning is one aspect of a broader revival of interest in analogue computing, aiming at many-variable machine-learning tasks. We briefly comment on the relation to other approaches in the conclusion. And we introduce a conjecture that no physical learning system with pairwise reciprocal interactions (i.e. one where the state minimises an energy function) can efficiently learn ICL tasks.
with two matrices W and a bias vector b of adjustable parameters. Here is a common choice of activation function, although many others have been used. If we set , then it is not surprising that any smooth function can be approximated by this formula.


Figure 1: Circuit simulating a relu-MLP, similar to [18, 2], with inputs supplied as and one output . The hidden nodes have alternating diodes to/from ground, enforcing , , ..., and the input at which the diodes turn on or off can be adjusted using the resistors to , which are fixed bias nodes. Closing the switch introduces nudge current for training, calculated from (4). Plot at right shows steps of training this circuit by gradient descent to match the datapoints shown, by adjusting all resistors. The flat segment where all diodes are off is a simple example of a circuit failing to learn a function it is able to express.
The approximation is piecewise linear, and each hidden node adds another kink whose position and slope can be adjusted, so that for large we can make small. This can be proven for any dimensionality and a wide class of activation functions [16, 17].
Figure 1 shows a circuit implementation of this MLP, in which adjustable resistors encode the parameters. The input is supplied by fixing node voltages to , but because resistance cannot be negative, we supply also inverted inputs. The diodes connecting the hidden nodes to ground implement relu nonlinearity, but we similarly need them in both directions to implement and separately. More subtly, while entries in can be large allowing any linear combination, the output resistors cannot amplify. For this reason the input nodes are amplified by a factor , to fix voltages as follows:
The output is read directly from some other voltages:
For , this circuit gives a piecewise linear function . At each kink a diode turns on or off. (But the number of kinks can be larger than the number of diodes, as the hidden nodes are shifted by the output layer — see figure S1 in the appendix.) The function obeys a slope constraint , and the universal approximation results of [2] for this circuit take both the amplification factor and the number of nodes to be large.
This circuit can be trained using the equilibrium propagation scheme of Scellier and Bengio [1]. First the input is supplied, and we write for the resulting steady-state node voltages. If the desired output is and the loss function is , then the nudged state is made by injecting the following current into the output nodes (closing the switch in figure 1):
Here sets the scale of the nudge, and indicates that the current flows from ground. Consider a resistor between nodes and with conductance . If its voltage drop is , then gradient of the loss with respect to its conductance can be estimated by comparing the free and nudged voltage drops [1]:
Gradient descent with learning rate is then, as usual, this update:
Such an update can be performed locally, seeing only the voltages at this particular resistor (provided can be memorised until the nudged phase). This local learning property is the key attraction of equilibrium propagation and other physical learning schemes. All of the transport of information, in both directions, happens in the circuit.
A variant of this scheme introduced by Stern et al. [19] clamps the output nodes to fixed voltages, instead of injecting a fixed nudge current. If we observe voltage in the free state, then the clamped state imposes
The voltage source used to fix this output node injects a current proportional to , so at each node this amounts to choosing scaled by the output impedance: . (Here is the voltage scale of the loss, needed for units, see below.)
Related two-phase training schemes have a long history, originally applied to Boltzmann machines [20] and Hopfield networks [21] under the name contrastive Hebbian learning, and later to MLPs [22, 23].
2.1 Double and dyadic circuits
Instead of allowing the circuit to settle to free and nudged states at different times, we now introduce a double circuit which does both at once. But unlike the twin circuits of Dillavou et al. [6], where free and nudged run on different copies of the hardware, in this double (or dyadic) circuit the free state and the nudge are the mean and difference of the two copies, as in [24, 4].
Figure 2 shows a doubled version of the MLP-like circuit in figure 1. The new circuit has 2N nodes, with voltages and . The input fixes 4n of them:
and the m outputs are constructed using 2m voltages, by taking the mean of original and primed copies:
Every resistor exists in two copies , and every diode, with no cross-connections.
What connects the two copies is that the training nudge is now delivered between original and primed output nodes:
producing differences elsewhere. The gradient is read from the difference in how the two copies behave:
For a circuit of resistors and diodes (such as the one in figure 2), this gradient formula is in fact exact for sufficiently small , small enough that no diode turns on or off.
So far this circuit of reciprocal components might be viewed as a circuit version of Høier et al. [24], which was expanded in [5] to allow linear non-reciprocal interactions. This was generalised to arbitrary

Figure 2: Double version of the circuit in figure 1, equipped with a floating loss function. Every node and every resistor or diode is duplicated, but the input clamps for instance so we identify . The output is now , explicitly computed by a voltage divider with large fixed . For training, the gradient of MSE loss is provided by a VCCS (fully differential OTA), which compares this output voltage to to create the nudge current , and ultimately produces at other nodes. The circuit has the same 15 parameters as before, as we maintain during training. An exactly dyadic circuit could not use ordinary diodes, and would instead couple their behaviour so that and are either both zero (off) or both nonzero (on).
differentiable dynamical systems by Scurria et al. [4], and we will describe as “dyadic” those circuits constructed according to their rules, while using “double” for a wider class of circuits with paired nodes obeying (11). The dyadic rules make the gradient estimate (11) true for any , thus the circuit in figure 2 is not in fact exactly dyadic (in this usage). This is because its diodes switch independently, while the dyadic counterpart of a single diode is two diodes locked to be both on, or both off, according to the mean of their voltage differences — see appendix A.3.
This circuit is also an implementation of the symmetric nudging idea of Laborieux et al. [25], who showed that two nudge phases of strengths resulted in more precise gradient estimation. Before returning to questions of non-reciprocal elements, we show how the nudge may be physically generated within the circuit's analogue world, so that there is only one phase of training, not two or three.
2.2 Loss as a circuit component
Suppose the loss function is mean squared error (MSE):
Note aside that the clamped training scheme (7), voltage mixing with , is equivalent to a nudge of strength following from this loss function:
where G is the Thevenin conductance matrix at the output nodes, evaluated at the free operating point, and are voltage and resistance references to make loss dimensionless. This equivalence should be valid for any reciprocal circuit, not just resistors and diodes, but may be broken by the active circuits below.
where ensures the loss is dimensionless. Then the nudge current for the doubled circuit is this:
If we regard as the voltage of an additional node, then the nudge is one more circuit element: a linear voltage-controlled current source (VCCS), i.e. a fully differential operational transconductance amplifier (OTA). This is drawn in figure 2. With such a circuit element inserted, the training scheme now has only one phase: the input and target voltages are applied simultaneously, and when the double circuit settles to a steady state, the gradient can be immediately estimated from (11). We do not need to read the free behaviour, and then decide what nudge to apply, from outside.
Other loss functions can similarly be implemented as floating circuit elements. Cross-entropy loss is the usual choice for classification tasks such as MNIST, and was used by [25, 26] for equilibrium propagation (training circuits equivalent to convolutional neural networks). For this loss function, output from a neural network is first transformed to probabilities by softmax. Our version includes a temperature :
and clearly . This distribution is then compared to a supplied target distribution using cross-entropy, giving the following loss function:
The raw outputs are termed logits, and the function which accepts them is logit cross-entropy (LCE). This loss function penalises low probabilities of the correct label more heavily than high probabilities of incorrect labels. And it is invariant to overall shifts . Such shifts do not affect the identity of the largest output, , hence do not affect classification accuracy.
The nudge current required for LCE is . We have an implementation of this as a floating circuit element, exploiting the exponential current law of the MOSFETs to implement softmax using same “bank” circuit shown in figure 6. We describe the full circuit in appendix B.
2.3 Perfect voltage multiplier
Now we wish to introduce nonlinear, non-reciprocal circuit elements, while still allowing for the bidirectional flow of information. Rather than thinking about slight perturbations around the above case, we proceed immediately to the opposite extreme, by inserting another ideal voltage-controlled current source.
Voltages can be multiplied by a circuit of 6 transistors called a Gilbert cell [27], which measures two pairs of voltage differences and , and then drives current between two additional nodes, say and . The simplest ideal version is a voltage-controlled current source, with current law
where K is a fixed gain. Besides these 6 terminals, the cell must of course be connected to a power supply.
A simple circuit containing one Gilbert cell and three resistors is drawn in figure 3, whose output voltage is . Here the Gilbert cell has half its nodes connected to ground, so its current law is

Figure 3: Simple multiplier circuit using an ideal Gilbert cell, a six-terminal device with three connected to ground here. Nudging the output of the circuit on the left cannot perturb node , before the multiplier. In the dyadic version of the same circuit (on the right), each node and each resistor is duplicated, but the multiplier is replaced with four multipliers: one in each copy, one reversed, and one providing a correction term. (Some connections to ground are not shown.) With this configuration, a nudge of order applied to will preserve all mean node voltages exactly, while has gradient information about and .
It should be obvious that a nudge of the output node in figure 3 cannot have any effect on the part of the circuit left of the Gilbert cell. Hence , so we gain no information about , and cannot tune resistor .
This problem can be fixed in the doubled circuit by inserting (in addition to the obvious duplicate) additional multipliers, some facing the other way. To derive what is required, we construct the dyadic potential of [4]. At each free node , this multiplies by the current leaving the node. For the circuit in figure 3 it reads
Each term arises from a component, and the currents required in the dyadic circuit may be read off as derivatives of this potential. For the Gilbert cell, these currents are:
(20)
There would be similar currents into nodes 3, 3' if these were not fixed. Assuming , the two backward current terms are simple to implement, as a single 6-terminal Gilbert cell can sense and drive , to give
For the forward currents, expanding gives a set of four forward multipliers, each working relative to ground. But the same currents can be produced by just three multipliers — the original one, its obvious double, and a correction term:
These three forward multipliers, and one reverse (21), are drawn in figure 3.
We review this dyadic construction at greater length in appendix A, and introduce an approximation which drops terms (but is exact for case above). It is always possible to specify a dyadic circuit using the rules of [4], but there is no guarantee that it can be implemented from the same components — that is a special property of multiplication. Arguably it's the same special property which makes resistors their own dyadic doubles, with no extra backward components. The next section explores this in an informal way.
2.4 Aside on automatic differentiation
The reverse multiplier introduced in figure 3 is reminiscent of the reverse operations inserted computing gradients in digital neural networks — we might guess the connections, if not the K/2 factor. This dyadic construction is deeply connected to automatic differentiation, but not quite so simply, because the different “layers” of the circuit from input to output aren’t just functions acting one after the other. This section reviews reverse-mode automatic differentiation in its simplest form, to gain intuition.
Given a function and a scalar loss function , the essence of back-propagation is to transform into . If we regard and as living on two different manifolds, then the map required is called the pullback of in differential geometry, written . This is always linear (it's a homomorphism between cotangent vector spaces, , [28, 29]) but it may depend on . One simple example is:
Given a long chain of functions, like , the gradient (or error signal) can be pulled back through each in turn, .
This procedure was used early on for digital simulations of analogue circuits [30], as well as for neural networks [31, 32]. Computer scientists stress is that the complexity of finding the gradient is times that of the original function, rather than growing linearly with the number of inputs [33]. This is also true of our doubled circuits.
If the function is multiplication, , then there are two pullbacks, one for each argument, and both involve multiplication:
That is precisely the form seen above, where plays the role of : one input of the reverse multiplication is the error signal of the output, while the other ( above) is part of the input.
The circuit law for resistors is also multiplication, and this is why its dyadic circuit element is just the same resistor again. Something similar is true for diodes, which are (at any given operating point) a limiting case in which the resistance is either 0 or . However, the effective resistance of both diodes should depend on the same , hence an independent pair of diodes (as in figure 2) is not quite the exact dyadic double.
2.5 Ideal sub-threshold MOSFET
An ideal transistor conducts current between two nodes, source and drain, with a conductance controlled by voltage at a third, the gate. There are many types, and they obey relatively simple laws in particular limits of their node voltages. Within physical learning, MOSFETs in the triode regime have been used as slightly nonlinear adjustable resistors, with their gates connected to a capacitor to control the resistance [6]. We're instead going to use them in the sub-threshold (or weak inversion) regime, where current varies exponentially with the voltages, because these exponentials will allow us to implement attention below.
The notation is standard, but be warned that these gradients are in the dyadic circuits, not the mean as the bar might suggest.

Figure 4: Comparison of a Bahdanau-like score function [8] to the dot product, applied to unit vectors in two dimensions (left) and ten dimensions (right). In two dimensions, the vectors are and , and we sweep for various fixed , with in bold. In ten dimensions, we show pairwise comparisons between 30 different random unit vectors. The claim is that this captures much of what the dot product captures, although it lacks rotational invariance.
Our ideal device is a 3-terminal component (gate, source, drain) with the following current law [34]:
with constants , , , . No current flows through the gate. This law is valid for voltages , or equivalently, current .
Below we use three different circuits in which a current source is connected to the source terminal of several transistors, shown in figures 5, 6, and 8. Their gates control how this current is shared among their drains, and the exponentials give us useful functional forms.
The dyadic circuit component necessary for a MOSFET to pass error signal backwards is quite complicated. What we do below is, instead, to construct more realistic approximately dyadic versions of these larger blocks. Quite crude approximations, much worse than , are nevertheless sufficient for learning.
2.6 Adaptive, local, optimisation rules
The scheme above uses gradient descent (6) to update parameters, but this is the most naive algorithm for using the gradient to perform optimisation. Better algorithms often try to estimate the Hessian of the loss function using some memory of past gradients [35], but for efficiency, most of the algorithms used with neural networks estimate only the diagonal of the Hessian. This means that they obey the locality criterion of physical learning. The most famous member of this class is probably Adam [10], and we show in appendix C how to implement the simpler Lion [11] which stores just one number per parameter. These adaptive rules are invariant to the scale of the gradients (they have learning rate with units of conductance, not conductance-squared) which will be important in circuits with exponential voltage dependence – like the transformer we construct in the next section.
3 Transistor transformer circuit
Every transformer is a sequence model, which we will write as , where the input X is a matrix whose columns encode successive tokens in the input sequence, , and the output y gives a probability distribution for the next token. The core operation is dot product self attention [3], which

Input (with )
Figure 5: Delbrück's bump circuit [7], which we use to replace the dot product. Here is divided three ways by four transistors, with the one output current gated by both inputs. Plots show the output (varying at fixed ), and the effect of nudging output on the inputs , . The exact dyadic circuit produces the expected gradient, while the crude approximation we use with Gilbert cells (in red) differs greatly away from the centre of the bump, but nevertheless allows training to move towards or away from the bump as necessary. (These plots rely on embedding the bump in a larger circuit, and thus depend on impedance of this apparatus.)
in the simplest (single-headed) case looks like this, with three weight matrices W:
Here we write vector indices ; often the range of is smaller making the matrix low-rank. The output for the last token is , and if this is what we want, then we need only compute elements , with .
Our goal here is to translate these pieces to active circuit elements, and then to construct a double circuit with approximate reverse elements, so that the weights W can be learned. One important approximation we make is to replace the dot product with something like Bahdanau attention [8]:
This is largest when the key and query vectors agree, and declines as any components begin to disagree, although it never becomes negative — see figure 4. We will also simplify by assuming this weight matrix is diagonal with positive entries, on the grounds that other transformations can be absorbed into .
The learned weights W are implemented by arrays of resistors, much like the earlier MLP layer in figure 1. The nonlinear parts use transistor circuits shown in figures 5, 6, and 8, and we now discuss them one by one.
3.1 Scores as currents from “bump”
Delbrück's simple bump circuit [7] has four transistors controlled by two gate voltages, , and gives a similarity score as a current. A fixed current source is split into three paths: one gated by


Figure 6: Three transistors dividing fixed to produce currents which behave like softmax of the input voltages [9, 36], in a circuit we call “bank”. The first plot shows its three outputs as is varied, holding fixed , . The second plot shows one column of the Jacobian, i.e. the error signal measured at the first input when each of the three outputs is perturbed by a nudge current. We find it necessary for training to use a fairly elaborate reverse circuit block which closely follows the ideal dyadic behaviour.
, one gated by , and a third limited by two transistors in series, whose gates are and , which is the output — node 5 in figure 5. When the voltages and are equal, current flows through all three paths, with 20% to the output. But when either voltage is increased or decreased, one of the drain paths is favoured, decreasing the output. After some algebra, the output current is:
With two vectors of voltages, we can use D such circuits, and add the resulting currents:
This will play the role of above, with implemented as a crossbar array with inverted inputs: resistors (as used for the MLP above). We take to be diagonal and all-positive, thus , implemented as a resistor divider to ground for each , thus 2D resistors for each s. We need to apply the same array of resistances to every , which we do with 2DT resistors in which each group of T must be updated together during training. Finally, between these resistor arrays and the bump circuit, we add a fixed voltage , which cancels out of (28) but increases the current through each transistor.
In the doubled circuit, there is a second copy of the bump circuit, with obeying the same law. We still need to pass gradient signal from back to the inputs, to ultimately train and . The sign of this signal must change as we pass from to . One simple idea is to use a Gilbert cell, or rather four of them:
where . The effect is shown in figure 5: it makes large errors far from where the bump is high, but still allows optimisation to find the top.
3.2 Attention as currents from “bank”
The softmax operation (15) distributes probabilities among T outputs, exponentially weighted by T inputs. This has a natural transistor implementation in which a fixed tail current is distributed

Figure 7: Resistor-feedback transimpedance amplifier, using an ideal VCCS (or operational transconductance amplifier, OTA). Given input current , the output voltage is . Our circuit uses these to convert current outputs from “bump” to voltage inputs for “bank”.
among T outputs, with each input controlling the gate of one transistor [9, 36], as shown in figure 6. We call this circuit “bank”, and its output is the following T currents:
With our NMOS conventions, the fixed tail current is a sink, and so the output signal is high current flowing into the bank at the s for which is largest.
The exact dyadic element has a backward current source obeying (for case s = 1, and T = 3 as in the figure)
where
After experimenting with various crude approximations, we eventually use a double circuit which stays quite close to this ideal, as demonstrated in figure 6. It involves a 2T-wide forward bank responding to the mean, with a voltage divider creating ; one VCCS/OTA sensing each output and driving a pair of reversed banks. Appendix A.6 has more details.
3.3 Current to voltage amplifier
This softmax-like “bank” circuit isn’t fed by the “bump” scores directly, for several reasons. Each block accepts voltage but outputs current, and a high score is a large negative current but needs to become a positive voltage. In addition, the reverse elements of “bank” will disturb the forward output of “bump”.
The missing link is the current-to-voltage amplifier shown in figure 7, which inverts with small input and output impedance 1/G, and gain controlled by a large resistor. In this arrangement the VCCS emits current , all of which flows back through the resistor, to give , and flows to the input current source, thus . Solving, the output is then (defining ):
In the full circuit, comes from bump, and this then controls the bank. (Each output like is also pulled up by a large resistor connected to fixed node. This voltage offset cancels out of (31), but increases the current through the transistors.)
In the doubled circuit, the dyadic potential contributions of the resistor plus VCCS are . These can be implemented using a similar amplifier


Figure 8: Differential pair mixer circuit. Here the tail current is an input from bank, while its voltage inputs will be a token. It produces a pair of currents , plotted against for various . Our reverse circuit provides a gradient signal only for ; notice that it correctly changes sign at .
in the primed half, and two floating VCCS: one to pass the error backwards, the other to correct the forward result, much like the Gilbert cell in section 2.3 above:
(35)
Note aside that this amplifier is very different to the bidirectional amplifier of Kendall et al. [18]. There, within a single circuit, they inserted an active device which multiplied all voltages to the right by A, and divided all currents to the left by A. This is an active element but their circuits insert always a line of them, making the whole system gauge-equivalent to a reciprocal, passive, circuit.
3.4 Value mixing with differential pairs
We need to use the output of the softmax to create a mixture of the inputs at different times . The differential pair we use here may be thought of as variant of the “bank”, taking as the gate voltages. But instead of a fixed tail current, we divide up the current , as drawn in figure 8. Its output is the following pair of currents (for one time and one feature ):
We connect all the for different s but the same together, and ground them through a load resistor. And similarly all the . Thus a set of T differential pairs gives two voltages which obey (for one feature ):
This is the desired mixing of different timepoints weighted by the softmax output. The tanh nonlinearity is unimportant but harmless, as we control the amplification factor of the input (i.e. the scale of in Volts).
We need D such sets of T differential pairs, one for each feature . In principle all could be driven by the same bank output. But each draws some current, and the naive wiring means they interfere with each other. Our solution at present is to simply have D equivalent bank circuits driving them.
For the gradient of the differential pair mixer, we again use Gilbert cells to read and from the output, and send current back towards “bank” via :
| Layer | Circuit (N = 497 nodes) | Double circuit (N = 1198) | Parameters |
|---|---|---|---|
| Key (array) | 120 resistors, 60 VS | 240 resistors, 120 VS | 12 |
| Query (array) | 288 resistors, 12 VS | 576 resistors, 24 VS | 288 |
| Scores (bump) | 240 transistors, 60 CS | 480 transistors, 120 CS, 240 multipliers | 0 |
| Amplifier | 5 VCCS, 10 resistors | 20 VCCS, 20 resistors | 0 |
| Attention (bank) | 60 transistors, 24 resistors, 12 CS | 480 transistors, 168 resistors, 36 CS | 0 |
| Mixing (pairs) | 120 transistors | 240 transistors, 120 multipliers | 0 |
| Value (array) | 144 resistors | 288 resistors | 144 |
| Loss (LCE) | — | 6 transistors, 12 VCCS, 24 resistors, 1 CS | 0 |
| Total | 1155 components | 3217 components | 444 |
Table 1: Component counts for the training task. Here , , and . VCCS is a floating voltage-controlled current source, CS is a fixed current source, VS is a floating voltage-difference device, multiplier is an ideal Gilbert cell. Counts do not include the input and target voltage sources. The rightmost column is the number of independently trained resistances, which is unchanged by doubling.
with involving a reference tail current at which the slope matches. This current captures the important feature of the true gradient that it changes sign when does – see figure 8. Since there is only one layer we do not supply an error signal towards the gates (i.e. towards ).
The final output comes from another resistor array, , implementing the value weights, roughly
3.5 Limitations
The circuit described here is an idealised sketch, and not a realistic engineering design. The circuit elements we employ have all been built, with approximately the functional properties shown, but they have limitations which our simulations do not model. Even in this sketch, there are many parameters tuned — tail currents, fixed resistances, etc — which help match the different layers. We are quite certain there are designs which are more realistic, more elegant, and use fewer components.
Table 1 lists the components needed for each of the layers described. Here we take , , and , which is the size of the model trained to perform in-context learning in the next section. We observe that the double circuit is larger by an factor, rather than growing with the number of parameters — the same property as reverse-mode automatic differentiation [33].
This model has 444 learned parameters, which is an order of magnitude larger than the breadboard self-learning circuits of [37]. But still smaller than the crossbar arrays of [38] with TaOx cells, used there to simulate an MLP with 1000 parameters.
4 Minimal in-context learning task
In-context learning (ICL) is the name given to some kinds of generalisation at which transformers excel [39]. It is often contrasted to memorisation [12, 13], and can be illustrated by examples like this:
-
Q: "Who was the first man on the moon?" A: "Neil Armstrong". Clearly his name had to be memorised, stored in the trained weights.
-
Q: “Anna & Grzegorz walked up the hill this morning, and Anna came down at lunchtime. Who is still up there?” A: “Grzegorz!”. Here the question in the second sentence doesn’t have a unique answer, but (having learned the rules of English) it’s easy to solve by copying letters from the first sentence, even if the name is unfamiliar.


Figure 9: Input matrices for the in-context learning (ICL) task, adapted from [13, 41]. Left, each character of string “L4 A1 T2 E5 N9 T” is a 20-dimensional embedding vector, with letters (random) and numbers (“one-hot”) alternating in time. They are accompanied by a simple time-code, in which the nonzero is incremented from a random start. This input needs a two-layer transformer, and the first layer’s function is to pay attention to time to encode letter and number together, giving a result like the matrix shown at right. Right, the 6-dimensional embedding vectors for a letter and a number are concatenated to one 12-dimensional vector, for each pair in “h2 u6 n4 c3 h?”. The desired output is , representing “2”. This task can be learned by a one-layer transformer, which must pay attention to time where the vector representing the query “h” appears. The , case shown is precisely the task studied in this paper.
The transformer here receives the question encoded such that each letter is a column of the input matrix X, and gives probabilities for the next character. Repeated sampling generates the answer string.
The associative recall task we use here has a much simpler grammar than English, and consists of strings like “a1 e5 c3 a?”, where the task is to predict the last character [40, 12, 13]. Every string in the training set has the answer appearing earlier, so that this can be solved by looking backwards, finding the matching token “a”, and copying the number after it, “1”, as the answer. If all the strings use a fixed letter-number relationship (like a⇒ 1, b⇒ 2, ...) then this can also be solved by memorising this relationship. The network will tend to learn just one solution, and the training data determines which is easier [12, 13] — see appendix D for more details. Here we use a large number of letters to ensure that ICL is preferred.
Input matrices for this task are shown in figure 9. If these letters and numbers alternate (i.e. occupy even and odd columns of the input matrix) then this task needs two attention layers, or one induction head. But if the vectors representing letters and numbers are concatenated (so that “a1” is one vector with entries for “a” followed by entries for “1”) as in [41] then a single attention layer is sufficient. This is the simple case we study, using the electrical circuit introduced above.
For training to succeed, we find it essential to use both LCE loss (not MSE), and to use an adaptive optimiser such as Adam or Lion (not gradient descent). Figure 10 shows training progress, using either exact gradients, or the crude approximate gradient components introduced above. We choose the initial resistors randomly, log-uniform in , and constrain them during training to this same range.
To test ICL accuracy, we use test cases like “β2 ζ6 ε5 ζ?”. That is, we generate new embedding vectors outside the training set, and check that the circuit is able to match these and route their companion numbers correctly [13]. Figure 10 uses a fixed test set of 256 examples, created using 200 new random embedding vectors.

Figure 10: Successful training on the ICL task, using either exact gradients (dyadic circuit) at left, or approximate versions at right. We track accuracy both at the final output, and also by looking at whether the score is highest at the time s which contains the solution. A random output will have accuracy , but simply copying a random part of the input (without attention) will give accuracy . All use Lion with and . The training data uses distinct “letter”s encoded as unit vectors in to make memorisation difficult; see appendix D for other cases.
5 Conclusion
In this paper we have shown how to construct a transformer-like architecture which allows for physical learning. In some sense this is an engineering project — we’ve translated an architecture known to have certain learning properties to a different substrate, and translated also the reverse pass and the training law. We brought together a range of ingredients to achieve this. But the idea of translating a known architecture to allow physical learning is familiar, except that it’s mostly been done for 20th century architectures: multi-layer perceptrons (MLPs) [18] and convolutional nets [25].
However, we’d like to claim a slightly grander view as motivation. Engineering unconventional hardware isn’t the only motivation for thinking about physical learning; instead, we hope that learning about learning in many contexts may ultimately teach us about how biology learns. While MLPs were motivated by networks of biological neurons, the extreme un-realism of training them by back-propagation has been a longstanding flaw in this analogy, famously noted by Crick [42]. In this light our work follows Lillicrap and Liao [43, 44] in asking how crude a variant of exact back-propagation might still work. But we add also a more difficult learning task.
The task we train the system to perform, a form of in-context learning (ICL), is quite different from any considered within physical learning. While feed-forward networks (like MLPs) have no trouble learning classification tasks like MNIST digits, these associative recall tasks appear to be very difficult for them to learn. Such tasks are at the core of our best understanding of what makes transformers so different from earlier models [14, 45]. Of course we don’t think the brain is literally a transformer, but we do think that our ease of solving such tasks ought to draw attention towards architectures which are able to do so. Toy ICL tasks are, perhaps, a useful diagnostic of whether a small system has post-MLP learning abilities.
Physical learning has mostly concerned itself with physical systems of reciprocal pairwise interactions — the resistors and diodes of section 2, but also spring systems [46, 47] and pipe networks [19, 48], chemical interactions [49] and spin systems [50]. Our conjecture is that no such reciprocal system can efficiently learn ICL tasks — as sketched in figure 11. It’s hard to prove statements about inductive bias, and usually requires specifying many architectural details, as for instance in [51, 52]. We investigate numerically in appendix D; see also [53] for related work on ICL in digital neural networks. What the field of machine learning has been good at proving are results about what can be expressed

Figure 11: Our conjectured Venn diagram for physical learning systems. A digital MLP (with relu) is not a reciprocal system, but is equivalent to network of resistors and diodes. The transformer presented here has explicitly non-reciprocal interactions, and needs our doubled formalism to enable physical learning. It is good at learning the ICL task.
by different architectures. MLPs of sufficient width can express any function [16, 17], and the same is true of their circuit relatives [2]. Results about deep MLPs being exponentially more expressive [54] can surely also be reproduced. But expressivity is an upper bound on what can be learned, and often an extremely loose one.
While non-reciprocal circuits cannot in general be trained by blindly applying equilibrium propagation, a larger circuit always exists with the same forward properties, and explicit reverse propagation [4]. However, such dyadic circuits will in general be much harder to physically realise, as they require components with arbitrary new current laws. Our simpler doubled circuits use realistic components to transmit approximate gradient information. The number of reverse elements is an order-1 factor larger than the number of original forward components, parallel to complexity results for digital networks [33].
5.1 The broader landscape of unconventional learning
The physical learning systems we study here are part of a broader revival of interest in analogue computing, aimed at machine learning tasks presently performed by digital computers. Two major motivations are energy and time: for example, a circuit to multiply two voltages needs far fewer transistors than the digital one to multiply two floating-point numbers [55], and need only settle to its operating point once, instead of once per clock cycle. Most such systems are studied without the constraint that analogue physics transports both the “forward” or inference signal and the “backward” error signal, which we took as the definition of physical learning.
At the opposite extreme, the training can take place in simulation, before the physical system is constructed. The task we studied above is in fact so simple that we can just write down the weights required by hand, and could easily hard-wire the circuit. But in general this process is very sensitive to small defects, and various hybrid methods aim to train the system to compensate, for instance by measuring the physical output of each layer and simulating only a layer-wise gradient [56, 57]. These ideas have been applied to a wide range of physical substrates [58]. Most of them are, we believe, in the same learning class as MLPs. That is, most are essentially feed-forward networks without the comparison needed for associative learning. But there is no obvious bar to using hybrid methods on systems like the transistor circuit described here.
Hopfield networks [59] are another class of unconventional learning systems, in which memories are stored as minima of an energy function. The traditional test is how well they can reconstruct a memory from corrupted input — that is, the input is the initial value of a dynamical state, which then evolves back to the stored memory. This is a task quite unlike either digit classification or our ICL. Recently, a variety of Hopfield-inspired networks have been constructed which aim to capture more of the transformer's behaviour [60, 61, 62, 63]. These are often described as energy-based models, but energy plays a different role to its meaning in steady-state reciprocal circuits (like figure 1): in [60, 61] the application of a transformer layer is modelled as one step downhill in an energy, and in [62] there is a different energy per token. That is if is the token for sequence time , its evolution through one step downhill is
which allows non-reciprocal interactions between and . These models are trained by finding exact gradients of the forward process, and by construction they behave very much like transformers. The exception is the CET model of [63], where the output truly is the result of a minimisation over the output and hidden degrees of freedom, holding the input X fixed:
Here the energy contains terms like using an attention score similar to (26). They train this model by equilibrium propagation, and show that it can learn to reconstruct corrupted images. In our adaptation, appendix D.3, it learns memorisation but not to perform ICL — in line with our conjecture about the need for non-reciprocal interactions for this task.
Acknowledgements
We thank Pranav Kantroo and Matthew Leighton for helpful comments on a draft.
This work was aided by OpenAI's ChatGPT for Academic Researchers program. In particular, the simulation code and the tuning of all details of this circuit would have been a huge project before. None of the text was written by AI.
This work was performed in part at the Aspen Center for Physics, which is supported by NSF grant PHY-2210452.
References
[1] Scellier & Bengio, Equilibrium propagation: Bridging the gap between energy-based models and backpropagation, Front. Comput. Neurosci. 11 (2017) 24 [ :1602.05179].
[2] Scellier & Mishra, A universal approximation theorem for nonlinear resistive networks, Phys. Rev. Applied 23 (2025) 044009 [ :2312.15063].
[3] Vaswani, Shazeer, Parmar, Uszkoreit, Jones, Gomez, Kaiser & Polosukhin, Attention is all you need, :1706.03762.
[4] Scurria, Abeele, Mognetti & Massar, Equilibrium propagation for non-conservative systems, ICML 43 (2026) [ :2602.03670].
[5] Høier, Kalinin, Ernoult & Zach, Dyadic learning in recurrent and feedforward models, First Workshop NeuroAI Adv. Neural Inf. Process. Syst. (2024).
[6] Dillavou, Beyer, Stern, Liu, Miskin & Durian, Machine learning without a processor: Emergent learning in a nonlinear analog network, PNAS 121 (2024) e2319718121 [ :2311.00537].
[7] Delbrück, “Bump” circuits for computing similarity and dissimilarity of analog voltages, in Proc. Int. Jt. Conf. Neural Netw. IJCNN, (Seattle, WA, USA), pp. I–475–I–479, 1991.
[8] Bahdanau, Cho & Bengio, Neural machine translation by jointly learning to align and translate, ICLR (2015) [ :1409.0473].
[9] Elfadel & Wyatt, Jr., The “softmax” nonlinearity: Derivation using statistical mechanics and useful properties as a multiterminal analog circuit element, NIPS 6 (1993).
[10] Kingma & Ba, Adam: A method for stochastic optimization, ICLR 3 (2015) [ :1412.6980].
[11] Chen, Liang, Huang, Real, Wang, Liu, Pham, Dong, Luong, Hsieh, Lu & Le, Symbolic discovery of optimization algorithms, Adv. Neural Inf. Process. Syst. 36 (2023) [ :2302.06675].
[12] Chan, Santoro, Lampinen, Wang, Singh, Richemond, McClelland & Hill, Data distributional properties drive emergent in-context learning in transformers, Adv. Neural Inf. Process. Syst. 36 (2022) [ :2205.05055].
[13] Reddy, The mechanistic basis of data dependence and abrupt learning in an in-context classification task, ICLR (2024) [ :2312.03002].
[14] Olsson, Elhage, Nanda et. al., In-context learning and induction heads, Transform. Circuits Thread (2022) [ :2209.11895].
[15] LeCun, Cortes & Burges, The MNIST database of handwritten digits, ATT Labs Online 2 (1998).
[16] Cybenko, Approximation by superpositions of a sigmoidal function, Math. Control Signal Sys. 2 (1989) 303–314.
[17] Leshno, Lin, Pinkus & Schocken, Multilayer feedforward networks with a nonpolynomial activation function can approximate any function, Neural Networks 6 (1993) 861–867.
[18] Kendall, Pantone, Manickavasagam, Bengio & Scellier, Training end-to-end analog neural networks with equilibrium propagation, :2006.01981.
[19] Stern, Hexner, Rocks & Liu, Supervised learning in physical networks: From machine learning to learning machines, Phys. Rev. X 11 (2021) 021045 [ :2011.03861].
[20] Ackley, Hinton & Sejnowski, A learning algorithm for Boltzmann machines, Cognitive Science 9 (1985) 147–169.
[21] Movellan, Contrastive Hebbian learning in the continuous Hopfield model, in Connectionist Models, pp. 10–17. Elsevier, 1991.
[22] O'Reilly, Biologically plausible error-driven learning using local activation differences: The generalized recirculation algorithm, Neural Comput. 8 (1996) 895–938.
[23] Xie & Seung, Equivalence of backpropagation and contrastive Hebbian learning in a layered network, Neural Computation 15 (2003) 441–454.
[24] Høier, Staudt & Zach, Dual propagation: Accelerating contrastive Hebbian learning with dyadic neurons, PMLR 202 (2023) 13141–13156 [ :2302.01228].
[25] Laborieux, Ernoult, Scellier, Bengio, Grollier & Querlioz, Scaling equilibrium propagation to deep ConvNets by drastically reducing its gradient estimator bias, Front. Neurosci. 15 (2021) 633674 [ :2006.03824].
[26] Kerjan, Høier & Scellier, Training a predictive coding network on ImageNet using equilibrium propagation, :2606.03584.
[27] Gilbert, A precision four-quadrant multiplier with subnanosecond response, IEEE J. Solid-State Circuits 3 (1968) 353–365.
[28] Cartan, Leçons sur les invariants intégraux: Cours professé à la faculté des sciences de Paris, Nature 111 (1923) 217–217.
[29] Whitney, Geometric Integration Theory. Princeton University Press, 1957.
[30] Hachtel, Brayton & Gustavson, The costate equation of initial value problems and its discretizations to compute gradients in the reverse mode, research Report, IBM T.J. Watson Research Center, Yorktown Heights, NY, 1969.
[31] Amari, A theory of adaptive pattern classifiers, IEEE Trans. Electron. Comput. EC-16 (1967) 299–307.
[32] LeCun, A theoretical framework for back-propagation, in Artif. Neural Netw. Concepts Theory (Mehra & Wah, eds.), (Los Alamitos, CA), IEEE Computer Society Press, 1992.
[33] Speelpenning, Compiling Fast Partial Derivatives of Functions given by Algorithms. PhD thesis, University of Illinois at Urbana-Champaign, Urbana, IL, USA, 1980.
[34] Enz, Krummenacher & Vittoz, An analytical MOS transistor model valid in all regions of operation and dedicated to low-voltage and low-current applications, Analog Integr. Circ. Sig. Proc. 8 (1995) 83–114.
[35] Nocedal, Updating quasi-Newton matrices with limited storage, Math. Comp. 35 (1980) 773–782.
[36] Sillman, Analog implementation of the softmax function, :2305.13649.
[37] Dillavou, Guzman, Liu & Durian, Understanding and embracing imperfection in physical learning networks, :2505.22887.
[38] Yi, Kendall, Williams & Kumar, Activity-difference training of deep neural networks using memristor crossbars, Nat. Electron. (2022).
[39] Brown, Mann, Ryder, Subbiah, Kaplan, Dhariwal, Neelakantan, Shyam, Sastry, Askell, Agarwal, Herbert-Voss, Krueger, Henighan, Child, Ramesh, Ziegler, Wu, Winter, Hesse, Chen, Sigler, Litwin, Gray, Chess, Clark, Berner, McCandlish, Radford, Sutskever & Amodei, Language models are few-shot learners, Adv. Neural Inf. Process. Syst. 33 (2020) 1877–1901 [ :2005.14165].
[40] Ba, Hinton, Mnih, Leibo & Ionescu, Using fast weights to attend to the recent past, NIPS 29 (2016) [ :1610.06258].
[41] Nguyen & Reddy, Differential learning kinetics govern the transition from memorization to generalization during in-context learning, ICLR (2025) [ :2412.00104].
[42] Crick, The recent excitement about neural networks, Nature 337 (1989) 129–132.
[43] Lillicrap, Cownden, Tweed & Akerman, Random synaptic feedback weights support error backpropagation for deep learning, Nat. Commun. 7 (2016) 13276.
[44] Liao, Leibo & Poggio, How important is weight symmetry in backpropagation?, AAAI 30 (2016).
[45] Arora, Eyuboglu, Timalsina, Johnson, Poli, Zou, Rudra & Ré, Zoology: Measuring and improving recall in efficient language models, :2312.04927.
[46] Pashine, Hexner, Liu & Nagel, Directed aging, memory, and nature’s greed, Sci. Adv. 5 (2019) eaax4215 [ :1903.05776].
[47] Stern, Arinze, Perez, Palmer & Murugan, Supervised learning through physical changes in a mechanical system, PNAS 117 (2020) 14843–14850 [ :1910.09547].
[48] Anisetti, Scellier & Schwarz, Learning by non-interfering feedback chemical signaling in physical networks, Phys. Rev. Research 5 (2023) 023024 [ :2203.12098].
[49] Poole, Ouldridge & Gopalkrishnan, Autonomous learning of generative models with chemical reaction network ensembles, J. R. Soc. Interface. 22 (2025) 20240373 [ :2311.00975].
[50] de Bos & Serra-Garcia, Multimodal oscillator networks learn to solve a classification problem, npj Metamaterials 2 (2026) 3 [ :2502.12020].
[51] Li, Zhang & Arora, Why are convolutional nets more sample-efficient than fully-connected nets?, ICLR 9 (2021) [ :2010.08515].
[52] Malach & Shalev-Shwartz, Computational separation between convolutional and fully-connected networks, ICLR (2021) [ :2010.01369].
[53] Tong & Pehlevan, MLPs learn in-context on regression and classification tasks, ICLR (2025) [ :2405.15618].
[54] Poole, Lahiri, Raghu, Sohl-Dickstein & Ganguli, Exponential expressivity in deep neural networks through transient chaos, NIPS 29 (2016) [ :1606.05340].
[55] Sarpeshkar, Analog versus digital: Extrapolating from electronics to neurobiology, Neural Computation 10 (1998) 1601–1638.
[56] Wright, Onodera, Stein, Wang, Schachter, Hu & McMahon, Deep physical neural networks trained with backpropagation, Nature 601 (2022) 549–555 [ :2104.13386].
[57] Nest & Ernoult, Towards training digitally-tied analog blocks via hybrid gradient computation, Adv. Neural Inf. Process. Syst. 37 (2024) [ :2409.03306].
[58] Momeni, Rahmani, Scellier, Wright, McMahon, Wanjura, Li, Skalli, Berloff, Onodera, Oguz, Morichetti, Del Hougne, Le Gallo, Sebastian, Mirhoseini, Zhang, Marković, Brunner, Moser, Gigan, Marquardt, Ozcan, Grollier, Liu, Psaltis, Alù & Fleury, Training of physical neural networks, Nature 645 (2025) 53–61 [ :2406.03372].
[59] Hopfield, Neural networks and physical systems with emergent collective computational abilities., PNAS 79 (1982) 2554–2558.
[60] Ramsauer, Schäfl, Lehner, Seidl, Widrich, Adler, Gruber, Holzleitner, Pavlović, Sandve, Greiff, Kreil, Kopp, Klambauer, Brandstetter & Hochreiter, Hopfield networks is all you need, ICLR (2021) [ :2008.02217].
[61] Hoover, Liang, Pham, Panda, Strobelt, Chau, Zaki & Krotov, Energy transformer, Adv. Neural Inf. Process. Syst. 36 (2023) 27532–27559 [ :2302.07253].
[62] Dehmamy, Hoover, Saha, Kozachkov, Slotine & Krotov, NRGPT: An energy-based alternative for GPT, ICLR (2026) 129193–129214 [ :2512.16762].
[63] Høier, Kerjan & Scellier, Training a convergent energy transformer with equilibrium propagation, ICLR (2026).
[64] Galley, Classical mechanics of nonconservative systems, Phys. Rev. Lett. 110 (2013) 174301 [ :1210.2745].
[65] Stern, Guzman, Martins, Liu & Balasubramanian, Physical networks become what they learn, Phys. Rev. Lett. 134 (2025) 147402 [ :2406.09689].
[66] Mao, Griniasty, Sun, Transtrum, Sethna & Chaudhari, An analytical characterization of sloppiness in neural networks: Insights from linear models, :2505.08915.
[67] Pethick, Antonakopoulos, Silveti-Falls, Vankadara & Cevher, Training neural networks at any scale: An exposition, IEEE Signal Process. Mag. 43 (2026) 21–36 [ :2511.11163].
[68] Handley, Sivakumar & Miskin, Microchips that learn with local, physics inspired rules, APS March Meet. Abstr. (2025).
[69] Scellier, Goyal, Binas, Mesnard & Bengio, Generalization of equilibrium propagation to vector field dynamics, :1808.04873.
[70] Lee, Jiang & Berg-Kirkpatrick, Is attention required for ICL? Exploring the relationship between model architecture and in-context learning ability, ICLR (2024) 53175–53204 [ :2310.08049].
[71] Kantroo, Wagner & Machta, In-context learning can distort the relationship between sequence likelihoods and biological fitness, :2504.17068.
[72] Elman, Finding structure in time, Cognitive Science 14 (1990) 179–211.
[73] Hochreiter & Schmidhuber, Long short-term memory, Neural Comp. 9 (1997) 1735–1780.
[74] Cho, van Merrienboer, Gulcehre, Bahdanau, Bougares, Schwenk & Bengio, Learning phrase representations using RNN encoder-decoder for statistical machine translation, EMNLP (2014) [ :1406.1078].
[75] Scellier, A fast algorithm to simulate nonlinear resistive networks, ICML (2024) [ :2402.11674].
[76] Nagel & Rohrer, SPICE: Simulation program with integrated circuit emphasis, tech. rep., EECS Dept., UC Berkeley, 1973.
[77] Vogt, Hendrix, Nenzi & Warning, Ngspice User's Manual, version 47 ed., 2026.
Appendix

Input ( , )

Input x
Figure S1: Behaviour of the resistor-diode circuit shown in figure 1, with exactly three hidden nodes. Left, with randomly chosen resistors (log-uniform in to ) there are typically three nonzero slopes, and two or three kinks. Right, resistors can be found such that this has five nonzero slopes, and five kinks. This would be impossible for a real MLP with three hidden nodes, equation (1), and results from current through the output resistors from one hidden node perturbing other hidden nodes.
A Deriving current rules for bidirectional information flow
Here we show explicitly how to construct dyadic circuit elements using the formalism of Scurria et al. [4], and then discuss the approximations made for the circuit blocks in section 3. The dyadic construction of [5] is similar; it uses for instance in place of which produces deviations at . This is also related to Galley's doubled-history variational principle [64] with some important differences, including that the final physical solution there turns off the difference, , while [4] keeps it.
Consider a dynamical system where is the state and some parameters. Conservative systems are those where , and the standard setting for equilibrium propagation considers the interplay between minimising this energy and a loss function , as for example in [65]. Finding stationary states which minimise the augmented energy for different allows us to find gradients
and hence to minimise by gradient descent. Locally, an energy function exists iff , that is, the Jacobian is symmetric, or the system has reciprocal interactions.
For non-conservative systems, [4] introduce a dyadic system which has two copies of the original state, , and a dyadic potential defined
The new dynamics are then and . For a linear reciprocal system (such as the resistor networks below), this potential is , thus we have two identical copies with no interactions, and a stationary state at a saddle of . To allow equilibrium propagation, they consider an augmented potential . A stationary state then obeys
Thus the mean solves the original equation, while the difference is an error signal, proportional to . They show that, as a result, the gradient is
This is exact, with no limit required.
To apply this to electrical circuits, we take to be the total current flowing into free node , and to be the voltage at this node. We consider only DC circuits, so there is no time-dynamics , but the relations above concerning stationary states still hold. At the free nodes, is precisely the KCL. Besides the free nodes, our circuits include several at fixed voltages (including , ground).
Given a circuit with free nodes described by , the above procedure always gives a circuit with free nodes described by , with and . This dyadic circuit has the same parameters , perhaps the conductances of variable resistors. Further, suppose that we decompose the circuit into components
where each contribution depends on just a few node voltages, and influences only a few currents, together say . Then clearly there is a similar decomposition in the dyadic system:
where depends only on nodes . Both and depend on the same subset of the parameters. In general will describe a block of physical components. The current laws of this dyadic block may be read from
which follow from dynamics for above.
In this section we stay closer to the notation of [4], and in particular use for node voltages in the double/dyadic systems (while the main text uses .)
A.1 Resistor
As a warm-up example, we consider the simplest possible circuit element with
The currents are , which agree with energy (really half the power dissipated):
The contribution to the dyadic potential is
As advertised, this is the difference of two single-copy potentials, . The resulting currents are
which we can combine into two resistors, both sharing the same conductance :
A.2 Gilbert cell — figure 3
Recall that this is a 6-terminal object with current law:
In the circuit of figure 3, half the terminals are grounded, leaving just
The only current is into node 5, thus only matters here. The dyadic potential contribution is
The currents which dyadic components must deliver are then read from (A7):
Here we no longer assume that node 3 is fixed. The backward currents can be implemented by four floating Gilbert cells:
(A12)
For the forward currents, expanding gives a set of eight forward multipliers. Our approximation is to replace these by four — the original, the obvious double, and two correction terms:
This makes an error , which is . For the case in section 2.3 in the main text, so it becomes exact (and the two correction terms become one).
A.3 Diode
Consider a diode with small finite resistance 1/g when it is turned on, thus current law
and write , and . This has dyadic energy contribution
We can think of this as a 4-terminal component which responds to by changing its resistance on both paths and together:
The obvious simpler component is two independent diodes, which have instead
This differs when one diode is on and the other is off, and can introduce a difference the same scale as the error signal. This is why we write in equation (11) without further qualification.
A.4 MOSFET
Recall that our device has
Thus , and
from which we derive the 6 currents out of the dyadic MOSFET device. The important thing is that the dyadic component has , current flows back from the gate.
A.5 Bump — figure 5
This block has
with , fixed & positive (and nodes 3,4 internal). This “output” current flows into the device, and is current flowing out to ground. (Current is drawn from 3,4 which also connect to ground.)
Since current only affects one node 5, we need only , and get this contribution:
and then we can compute six current laws like
The physical approximation we use is this, a linearisation about the top of the bump, :
A.6 Bank — figure 6
This block has M inputs and M outputs, with:
defining . Let me take to match the figure. This draws current from each node with , hence the dyadic energy contribution is
The forward currents are like this
with evaluated at . We approximate these by evaluated at , and evaluated at , etc.
The reverse currents are more messy:
We tried a very crude approximation that ignores common channel C, which can be implemented by a single VCCS per input a:
With this variant we found settings at which we could learn the ICL task, but not the memorisation task of section D. Thus at present we use a more complicated circuit shown in figure S2. This is not ideal, it pulls current from all and for all inputs , but the TIA stage handles these currents well.
A.7 Pair — figure 8
This is a variant of bank in which the tail current is one of the inputs. Inputs are and outputs are currents at nodes 4,5:
(A23)

Figure S2: Bank has inputs 1, 2, 3 and outputs 4, 5, 6. At right we draw its doubled circuit, with the output nodes in the middle, and input nodes drawn twice. Forwards, a 6-wide bank responds to , explicitly invariant to input differences , and with independently created and to reduce interference. Backward, two 3-wide banks each respond to the same , shifted slightly.
Here the block involves 3 currents
anyway we arrive at dyadic potential
and thus
We discard the terms (one layer) keep only the last term, linearising the tanh around .
B Cross-entropy loss as a floating circuit element
Figure S3 left shows the same circuit element for MSE as we had in figure 2 in the main text, now for two outputs . Note that we draw each output node twice, so that the circuit reads left-to-right but influences its input. Note also that the loss element for each is decoupled from the others.

Figure S3: Loss-function elements. Left, generates the nudge appropriate for MSE loss, as drawn in figure 2 but now allowing m = 2 outputs. Each output node of the circuit is drawn twice: this fragment reads the mean outputs , , computes the nudge current by comparing to the given , and injects it back into the same nodes. Right, the equivalent for LCE loss. The middle part is the “bank” circuit from figure 6; its current outputs are converted to voltage by the 1Ω resistors. If driven directly by then the softmax temperature would always be ; the amplification stage lets us adjust this.
Figure S3 right shows a circuit implementing the following nudge current, which is the gradient of LCE loss (16):
The parts are as follows:
-
First, the mean output is found with a resistor divider between and , with large fixed .
-
These voltages are amplified, to allow control of the temperature . The first voltage, , is used as the reference, and replaced with 0. (Our circuit uses an OTA / VCCS device driving current into a resistor to ground, thus essentially simulating an op-amp.)
-
These voltages are the input to the bank circuit from figure 6, controlling the gates of m transistors with a fixed total current . The resulting currents are softmax( ) .
-
The “bank” output currents each drain to ground, to produce voltages. These voltages are compared to , supplied as voltages from outside. The comparison involves a floating VCCS, which drives current between the same output nodes.
C Adaptive optimisation rules with memory
Gradient descent is the most naive way to use gradient information to perform optimisation. Its two main limitations involve the shape of the landscape, and how to deal with noise in the gradient vector.
The problem is roughly to find where the objective is the mean of the loss function evaluated for all points in the training dataset :
Here is a neural network, or the output of a circuit with input voltages . We write to stress that this is all the parameters, for us a vector of all the adjustable conductances . We write for one element, with .
In the neighbourhood of its minimum, might be some quadratic bowl, often greatly elongated [66]. If so, then knowing the Hessian at that point, , would allow descent to the minimum in one step. Computing all second derivatives is very expensive, and methods like L-BFGS [35] aim instead to estimate the Hessian from past gradient observations:
One inspiration for methods like Adam is to estimate only the diagonal elements of the Hessian. This involves numbers, instead of .
In machine learning, we typically do not find the gradient for all training samples at once, but instead for just a small batch of them, . And in the physical training above, it's natural to use :
This is a noisy measure of the true gradient , hence this is described as stochastic gradient descent (SGD). Some noise is thought to have beneficial properties, regularising the solution, but not too much. One further function of optimisation rules is to smooth this noise out, simulating a larger by keeping a moving average of for some past times , and updating based on this.
For a recent review of optimisation rules focused on this two-fold role, preconditioning plus smoothing, see [67].
C.1 Adam [10]
For each scalar parameter , Adam stores two memories , initially zero. These are estimates of the first and second moments of the gradient , updated as follows at each time-step , with decay rates typically and :
(C4)
The parameter is updated as follows, with learning rate :
The update is essentially ; the other factors are corrections for starting at , which are applied only for small . Notice this invariance: a gradient (say) 10x larger makes 10x larger, and 100x larger, but has no effect at all on the updates to .
C.2 Lion [11]
This is a simpler optimiser, recently discovered by automated search. For each scalar parameter , it stores one memory . Then at each time-step , given gradient , the update rule is the following:
(C6)
Here is the learning rate, and it sets the size of the fixed steps . By default , meaning that is a moving average of about 100 past gradients. And means that a particular gradient which disagrees with this average and is about 10 times larger will immediately move the parameter. Clearly a gradient (say) 10x larger will, again, have no effect on the updates to .
If we set then Lion simplifies to use the memory directly for the update:
(C7)
This optimisation rule is what we're using for the physical training. And this rule could plausibly be implemented as an RC circuit. A local circuit for gradient descent must measure the voltage drops and (11) and use them to update conductance (6). A local circuit for Lion would instead have a capacitor which stores the memory , with RC time about 100 training examples, loaded by the gradient measurement. Then the conductance update has a fixed rate of change controlled by the sign of the memory, the learning rate, and the time between training examples:
We have not simulated a specific circuit for this, as we restrict our simulations to DC. But it would not be much more complex to build than the twin edge circuits of [6, 68].
D Transitions between ICL and memorisation
The in-context learning (ICL) task of section 4 is adapted from Reddy [13, 41], who showed a phase transition between generalisation and memorisation, i.e. between ICL and “in-weights learning”. This phase transition also occurs in our transistor transformer, as we show in figure S4. The rest of this appendix explains the task in more detail, and compares to some other models.
Let us be more explicit about the setup. Training involves:
-
A fixed set of class vectors, for . These are the embedding vectors of the letters in the main text. They are random, .
-
A fixed set of label vectors, for . These are the embedding vectors of the numbers in the main text. While [13] takes them to be random, we take them to be “one-hot” vectors . Since dot-product attention (26) is rotationally symmetric, this involves little loss of generality, as random vectors are nearly orthogonal for large . But our (27) breaks this symmetry.
• A fixed class-label relationship , which is generally many-to-one as .
- Each training sample is a sequence of N class-label pairs, plus one query class. In the training data, the query class always appears earlier in the sequence. In [13] the sample repeats B times, described as a burst, but we take B = 1. We take N = 4, and demand in addition that all N pairs use distinct labels. Thus random output has accuracy 1/L, but simply returning any one of the given sequence's labels gives accuracy 1/N.

Figure S4: Two training tasks: classes (“letters”) on the left, encouraging memorisation, and on the right, identical to figure 10. Here we use the physical approximate gradient elements. In addition to accuracy on an ICL test (red, as before), we also plot a blue line showing accuracy on a memorisation test (in which the answer does not appear earlier in the string).
- Noise is added to the class vectors, to ensure that for large enough it is impossible to memorise the class-label relationship, as different classes will overlap. As in [13] we use and we take .
There are two tests:
-
The test for ICL involves a completely new set of class vectors, and then constructs sequences as before.
-
The test for memorisation instead constructs sequences in which the query class does not appear earlier in the sequence.
Test and training sequences are assembled into matrices as follows:
-
For the two-layer model of [13], the vectors are columns of a matrix (with ). The full input matrix concatenates a simple time-code, which increments the position of one nonzero entry in each time-step, so that for .
-
For the one-layer model of [41], each pair is concatenated to one vector, and these are columns of the full input matrix. There is no need for a time-code in this case.
The circuit described in section 3 is a one-layer model, and is capable of learning either strategy. Features which increase the likelihood of learning ICL (because they make memorisation harder) are increasing K, increasing burstiness B, and increasing the noise.
Figure S4 shows training with K = 10 and K = 100. The case K = 100 is identical to figure 10 in the main text, except that we plot the memorisation test accuracy too.
For training accuracy and ICL test accuracy, solid lines use the output, but dashed lines count whether the score is highest at the correct input time s, for .
D.1 Single circuits and the VF algorithm
An early approach to applying equilibrium propagation to non-reciprocal systems in [69] proposed simply using (5) despite the lack of an energy function. This is known as the vector field (VF) algorithm,

Figure S5: Training using the VF algorithm, instead of the double circuit. At left, K = 10 encouraging memorisation, with partial success by training the output value resistors alone. At right, K = 100 should encourage ICL, learns nothing, as no gradient information propagates to the key and query resistors.
and figure S5 tries this with our transformer circuit, that is, applying a nudge without doubling the circuit first. To first approximation this trains only the output resistors, implementing . This is sufficient for some memorisation to emerge, but the network cannot learn to solve the ICL task without training the key and query resistors which control attention.
D.2 Memorisation in an MLP-like circuit
Figure S6 shows the result of training a resistor MLP on this task, precisely the model of 1 except enlarged to have i.e. 120 input nodes, 64 hidden nodes, and as 6 output nodes. This has 4352 trainable resistors, an order of magnitude larger than our transformer. It has no difficulty memorising letters, but we have not seen it learn to perform ICL.
D.3 Convergent Energy Transformer [63]
We adapted the CET model from [63] to suit our task, with matrix input ( , ) and vector output ( ). Their energy function can be written
(D1)
The parameters are
MLP, physical + Lion, K=10

MLP, physical + Lion, K=100
Figure S6: Training a resistor MLP instead of the transistor transformer. At left, encouraging memorisation. At right, should encourage ICL, but it cannot learn this task. The circuit used is as in 1, with 120 input nodes ( positive, and 60 inverted), 64 hidden nodes, 6 outputs. Even for and 512 hidden nodes we have not seen successful ICL.
and (single-headed) and (Hopfield memories). The forward evaluation of the model is then
with the hidden state constrained by
Our data has , and as before, and we vary and . We train using cross-entropy loss, exact gradients, and Adam. We see perfect memorisation of the data with classes, and ICL accuracy at chance for . That is, it behaves like the MLP of figure S6.
D.4 Artificial neural networks
Our statement above that MLPs struggle to learn this task ought to be quantified somehow. While ICL is often described as a key characteristic of how transformers work, it is not impossible to train an MLP to perform ICL, but it does require encouragement. While results above use K = 10 to see memorisation and K = 100 to produce ICL, figure S7 explores much larger K. Here we use ordinary digital neural networks. Similar results were obtained by [53].
Figure S7 also includes several kinds of recurrent neural networks (RNNs), and sees intermediate performance for these. The literature has varied results on RNNs learning ICL tasks, see for instance [12, 45, 70]. There are also results on convolutional networks such as [71].
E Nonlinear circuit solver
Finding the operating point of linear circuits amounts to one matrix inversion. For the piecewise linear circuits like figure 1, we can use the fast algorithm of [75] — with the caveat that it only handles

Figure S7: Transitions between memorisation and ICL for several artificial neural networks, using the same training task. Transformer variants (top) use (26) and (27), MLP variants (bottom) are (1) with 64 and 256 hidden nodes, and one with a second hidden layer. Three standard kinds of recurrent neural networks [72, 73, 74] are also shown (middle). Note that the models have widely varying parameter counts: 432 and 300 for the transformers, for the MLPs, for the RNNs.
diodes connected to a fixed voltage.
For the truly nonlinear circuits, we use a custom Newton-Raphson solver. The MOSFET circuits are badly conditioned, as the exponentials can take a wide range of values. Tracking a tiny nudge on top of that, accurately, is a challenge. The solution used in our solver is to change variables, and re-write the circuit equations in terms of and . There is no physical change here, and we do not for instance demand that is unchanged by the nudge.
The most common off-the-shelf solver is SPICE and its descendants [76, 77]. We have built a bridge across to this, and have confirmed that Ngspice is able to solve the final model produced by training (figure 10 “physical”) and achieves the same accuracy with the same ICL test data. We still use ideal components, especially transistors obeying (25) instead of a fully realistic law.