Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
2f7d363
build(deps): bump AiDotNet.Tensors + native packages 0.96.1 -> 0.98.0…
ooples Jun 16, 2026
3b53e85
feat(perf): COW clone lever (G6) — diffusion model param-share kills …
ooples Jun 16, 2026
3fd1658
feat(perf): COW clone for CogVideo + shared CopyOnWriteCloneHelper (3…
ooples Jun 16, 2026
9bcaaf0
feat(perf): full-fidelity NN COW clone — reflection walk + extras (#1…
ooples Jun 16, 2026
f5695e3
feat(perf): NN COW coverage guard — auto-fall-back when share is inco…
ooples Jun 16, 2026
3008aa1
feat(perf): enable NN COW DeepCopy by default — fixes trained-clone O…
ooples Jun 16, 2026
282bf83
feat(perf): G2 — 8-bit Adam optimizer state for large models (#1624)
ooples Jun 16, 2026
c2805b8
feat(perf): G8 — gradient micro-batch accumulation for large non-Batc…
ooples Jun 16, 2026
62b3e99
fix(perf): make G2/G8 memory levers reactive (engage on OOM, not by s…
ooples Jun 16, 2026
5447782
Merge remote-tracking branch 'origin/master' into perf/1624-training-…
ooples Jun 16, 2026
5ff6a5f
feat(perf): bf16 optimizer-state rung — proactive default for large m…
ooples Jun 16, 2026
113717b
test(perf): COW clone correctness — identical + independent under mut…
franklinic Jun 17, 2026
665514a
perf(diffusion): route Clone() through the global COW helper (light O…
franklinic Jun 17, 2026
dd80ac0
Merge branch 'master' into perf/1624-training-scale
franklinic Jun 17, 2026
d9b4dc3
refactor(perf): drop redundant object-graph COW overload (#1624)
franklinic Jun 17, 2026
3a8f6db
Merge branch 'master' into perf/1624-training-scale
ooples Jun 17, 2026
374987f
fix(diffusion): correct COW-clone regression on composed models (#1624)
franklinic Jun 18, 2026
d28039b
feat(#1624): streaming SetParameterChunks — flat-free param round-tri…
franklinic Jun 18, 2026
edba8fe
fix(#1624): lazy adaLN-zero init so foundation-scale FlagDiT/Lumina c…
franklinic Jun 18, 2026
3a2e97e
feat(#1624): streaming GetParameterChunks/SetParameterChunks on FlagD…
franklinic Jun 18, 2026
c31e3bf
feat(#1624): streaming param chunks on AsymmDiT / EMMDiT / SiT predic…
franklinic Jun 18, 2026
16bb537
feat(#1624): streaming param chunks on MMDiTXNoisePredictor (mixed la…
franklinic Jun 18, 2026
8010626
feat(#1624): streaming param chunks on MMDiTNoisePredictor
franklinic Jun 18, 2026
7153e9e
fix(#1624): UViT SetParameters truncation + Clone materialization + s…
franklinic Jun 18, 2026
16059a8
feat(#1624): G4 activation checkpointing for diffusion predictors (in…
franklinic Jun 18, 2026
3acf1a0
feat(#1624): replicate G4 activation checkpointing across single-stre…
franklinic Jun 18, 2026
8cc182d
feat(#1624): G5 quantization-aware training for diffusion (opt-in, ga…
franklinic Jun 18, 2026
3185c8d
fix(#1633 review): COW helper visibility+shape-check, input validatio…
ooples Jun 18, 2026
ad0112d
fix(#1633 review): validate SetParameterChunks input + COW-detach bef…
ooples Jun 18, 2026
00a238e
feat(#1624): G4 activation checkpointing for MMDiT (dual-stream) + UV…
franklinic Jun 18, 2026
c0ab970
fix(#1633 review): config-preserving Clone() for custom diffusion ins…
ooples Jun 18, 2026
a03014a
feat(#1624): G5 quantization-aware training default-ON for foundation…
franklinic Jun 18, 2026
5b18fa2
fix(#1633 review): predictor clone _posEmbed fidelity + chunk-setter …
ooples Jun 18, 2026
112d2db
fix(#1633 review): reactive-memory-lever + COW-coverage correctness
ooples Jun 18, 2026
2d3304d
test(diffusion): harden chunk round-trip + isolate global checkpoint …
ooples Jun 18, 2026
6ea4ab0
fix(1624): gate OOM-retry on mutation start + dedupe chunk helpers
ooples Jun 18, 2026
4f63a5f
Merge branch 'master' into perf/1624-training-scale
ooples Jun 18, 2026
4b8e419
build(deps): bump AiDotNet.Tensors family 0.98.0 -> 0.101.2
ooples Jun 18, 2026
9b179b4
docs(deps): record measured 0.98.0->0.101.2 #1624 repro numbers
ooples Jun 18, 2026
28c5434
fix(1643): pin lazily-materialized layer weights so an active arena c…
ooples Jun 18, 2026
e661c54
perf(bn): route batch=1 training fallback through Engine.BatchNormAff…
ooples Jun 18, 2026
ab17c8c
revert(#1624): remove G4 activation checkpointing — primitive is not …
franklinic Jun 18, 2026
9773ff5
fix(build): BatchNormalizationLayer inference affine without Engine.B…
franklinic Jun 19, 2026
c48ea2a
feat(diffusion): G4 activation checkpointing across DiT-family noise …
franklinic Jun 19, 2026
6b9668c
refactor(diffusion): make G4 activation checkpointing opt-in (PyTorch…
franklinic Jun 19, 2026
83fcb8d
Merge branch 'master' into perf/1624-training-scale
ooples Jun 19, 2026
819bc6c
fix(diffusion): G4 checkpoint as a single segment — exact under Fused…
franklinic Jun 19, 2026
f0af89f
feat(diffusion): G4 multi-segment (sqrt(N)) activation checkpointing …
franklinic Jun 19, 2026
79e4ab9
feat(diffusion): checkpoint MMDiT dual-stream joint blocks (#1624 G4 …
franklinic Jun 19, 2026
0d95b44
perf(conv): real depthwise convolution in ConvolutionalLayer + invert…
ooples Jun 19, 2026
37e208a
build(deps): bump AiDotNet.Tensors + native packages 0.101.2 -> 0.101.7
ooples Jun 20, 2026
4eeb55f
fix(diffusion): memory-aware weight-streaming engagement — keep fits-…
franklinic Jun 20, 2026
2994107
feat(diffusion): paper-faithful noise predictors — replace 5 Dense st…
franklinic Jun 20, 2026
aad5af2
perf(diffusion): route MMDiT attention through the fused FlashAttenti…
franklinic Jun 20, 2026
6751cf2
perf(diffusion): make QAT opt-in (default off), not auto-engaged by p…
ooples Jun 20, 2026
7ecf645
perf(diffusion): run eager forward under a training tape (skip compil…
ooples Jun 21, 2026
b2167fb
Merge branch 'master' into perf/1624-training-scale
ooples Jun 21, 2026
b9f2fbc
fix(diffusion): deterministic inference RNG — Predict reproducible fo…
franklinic Jun 21, 2026
0ed12e3
fix(diffusion): default compiled inference off (gate corrupts eager s…
franklinic Jun 21, 2026
31253c8
fix(nn): default compiled inference off (same gate scratch-corruption…
franklinic Jun 21, 2026
5e2794c
deps: bump AiDotNet.Tensors 0.101.7 -> 0.102.2 (Phase C mixed-precisi…
franklinic Jun 21, 2026
a4657be
feat(mixed-precision): loss-scale the SGD consumer path — Phase E (#1…
franklinic Jun 20, 2026
776e1cf
test(mixed-precision): Phase E guard — GradScaler API resolves on pin…
franklinic Jun 21, 2026
e0b561c
fix(inference): verify gate returns deep-copied compiled candidate on…
franklinic Jun 21, 2026
5c4fb5b
Merge branch 'master' into perf/1624-training-scale
ooples Jun 22, 2026
5510c5c
Merge remote-tracking branch 'origin/master' into perf/1624-training-…
ooples Jun 22, 2026
21d5546
Merge branch 'master' into perf/1624-training-scale
ooples Jun 22, 2026
8eab280
Merge branch 'master' into perf/1624-training-scale
ooples Jun 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 38 additions & 10 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,44 @@
gated on: Dense -> LayerNorm -> GELU -> Dense now routes its between-matmul ops through the
FP16-native path instead of the eager FP32 fallback. 0.96.0 supersedes master's 0.95.2;
Native packages coreleased in lockstep at 0.96.0. -->
<!-- 0.96.3: carried the FP16 non-Adam fused-optimizer fix —
FusedOptimizerIntegrationTests.Fp16Activations_NonAdamFusedOptimizer_DescendsLoss
(FP16 RMSprop) was a training no-op (bit-identical first/last loss) on 0.96.1; fixed there. -->
<!-- 0.97.2: published (from master); supersedes 0.96.3.
Native packages coreleased in lockstep at 0.97.2. -->
<!-- 0.102.3: latest published; carries #658 — forward-GEMM core saturation
default-on (s_forwardPackBothBlocking + s_singleRegion, opt-out
AIDOTNET_GEMM_FORWARD_PACKBOTH=0 / AIDOTNET_GEMM_SINGLE_REGION=0; ~1.3-2x on
transformer/training GEMM shapes) + net471 PackAOnly non-4x4 tail bugfix.
Native packages coreleased in lockstep at 0.102.3. -->
<!-- 0.101.2: latest published; supersedes 0.98.0. Pulls in the #1624-class OOM/perf work
(COW clone, byte-budgeted arena, fused-path per-step arena, streaming clean/dirty eviction,
activation-aware autotuner) that this PR's training-scale fixes build on.

Measured 0.98.0 -> 0.101.2 on the canonical #1624 leak shape (SimCSE<float> dim=384,
10 layers, fused-optimizer path under one never-Reset() outer TensorArena, CPU, 31 steps),
same local src, version the only variable:
* Peak RSS 1404 MiB -> 949 MiB (-32%, the number that OOMs the 16 GiB runner)
* Total alloc 2422 MiB -> 1173 MiB (-52%; alloc/step 78 -> 38 MiB)
* Per-step heap growth flat in BOTH (-0.001 MiB/step: the per-step leak fix is consumer
src, constant across the runs), and loss converges identically (1.27 -> 0.26) — the
reduction is not from silently breaking training.
0.101.2 -> 0.101.5: activation-checkpointing correctness, two fixes.
(1) #643 (0.101.4): GradientCheckpointing.Checkpoint's recompute differentiated only w.r.t.
the segment input, silently dropping every checkpointed layer's WEIGHT gradients.
(2) #645 (0.101.5): multi-segment recompute double-counted earlier segments — a later
segment's recompute followed its (non-detached) input back into the earlier segment's
checkpoint node, so earlier-segment gradients came out 2x. 0.101.5 detaches each
segment's input (matches torch.utils.checkpoint), making sqrt(N) multi-segment exact.
Both are required for G4 (#1624) in the diffusion NoisePredictors (sqrt(N) checkpointing) and
for NeuralNetworkBase checkpointing.

0.101.5 -> 0.101.7: the merged MobileNetV3 batch=1 timeout work and supporting fixes —
#639 batch=1 BatchNormAffine fusion (#641, required by BatchNormalizationLayer's batch=1
training fallback, which calls Engine.BatchNormAffine), Conv2D core-saturation (#647), the
nested-arena escaped-buffer #1221 fix (#648), the GPU resident-weight version-gate (#649),
and GPU conv-kernel arg-binding fixes (#644).
Native packages (OneDNN/OpenBLAS/CLBlast) coreleased in lockstep.
Bumped 0.101.7 -> 0.102.2: brings the #632 compiled-inference MemoryPlanning aliasing fix
(BlasBatch hoist vs memory planning in attention inference — the root cause of the diffusion
Predict_ShouldBeDeterministic failures, which reproduced on 0.101.7 and is gone on 0.102.x),
plus the Phase C fp16-weight / fp32-master mixed-precision storage (#650).

Bumped 0.102.2 -> 0.102.3 (from master, #658): forward-GEMM core saturation default-on
(s_forwardPackBothBlocking + s_singleRegion, opt-out AIDOTNET_GEMM_FORWARD_PACKBOTH=0 /
AIDOTNET_GEMM_SINGLE_REGION=0; ~1.3-2x on transformer/training GEMM shapes) + the net471
PackAOnly non-4x4 scalar-tail bugfix. 0.102.3 is a linear superset of 0.102.2, so the #632 /
Phase C deps above are retained. -->
<PackageVersion Include="AiDotNet.Tensors" Version="0.102.3" />
<PackageVersion Include="AiDotNet.Native.OneDNN" Version="0.102.3" />
<PackageVersion Include="AiDotNet.Native.OpenBLAS" Version="0.102.3" />
Expand Down
4 changes: 2 additions & 2 deletions src/Diffusion/Audio/AudioLDM2Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ private Tensor<T> GenerateWithDualEncoders(
}

// Initialize random latent
var rng = seed.HasValue ? RandomHelper.CreateSeededRandom(seed.Value) : RandomGenerator;
var rng = CreateInferenceRng(seed);
var latent = SampleNoiseTensor(latentShape, rng);

// Set up scheduler
Expand Down Expand Up @@ -689,7 +689,7 @@ public virtual Tensor<T> TransformAudio(
var startTimestep = Scheduler.Timesteps.Skip(startStep).FirstOrDefault();

// Add noise at starting timestep
var rng = seed.HasValue ? RandomHelper.CreateSeededRandom(seed.Value) : RandomGenerator;
var rng = CreateInferenceRng(seed);
var noise = SampleNoiseTensor(latent._shape, rng);
latent = AddNoiseAtTimestep(latent, noise, startTimestep);

Expand Down
2 changes: 1 addition & 1 deletion src/Diffusion/Audio/AudioLDMModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ public virtual Tensor<T> TransformAudio(
var startTimestep = Scheduler.Timesteps.Skip(startStep).FirstOrDefault();

// Add noise at starting timestep
var rng = seed.HasValue ? RandomHelper.CreateSeededRandom(seed.Value) : RandomGenerator;
var rng = CreateInferenceRng(seed);
var noise = SampleNoiseTensor(latent._shape, rng);
latent = AddNoiseAtTimestep(latent, noise, startTimestep);

Expand Down
6 changes: 3 additions & 3 deletions src/Diffusion/Audio/DiffWaveModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public virtual Tensor<T> GenerateFromMelSpectrogram(
var shape = new[] { 1, length };

// Initialize with noise
var rng = seed.HasValue ? RandomHelper.CreateSeededRandom(seed.Value) : RandomGenerator;
var rng = CreateInferenceRng(seed);
var audio = SampleNoise(shape, rng);

// Set up scheduler
Expand Down Expand Up @@ -300,7 +300,7 @@ public virtual Tensor<T> GenerateBatch(
{
var shape = new[] { batchSize, sampleLength };

var rng = seed.HasValue ? RandomHelper.CreateSeededRandom(seed.Value) : RandomGenerator;
var rng = CreateInferenceRng(seed);
var audio = SampleNoise(shape, rng);

Scheduler.SetTimesteps(numInferenceSteps);
Expand Down Expand Up @@ -398,7 +398,7 @@ public override IDiffusionModel<T> Clone()
clone._network.ResolveLayerShapesFor(_lastInputShape);
clone._lastInputShape = (int[])_lastInputShape.Clone();
}
clone.SetParameters(GetParameters());
if (!clone.TryShareParametersFrom(this)) clone.SetParameters(GetParameters());
return clone;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Diffusion/Audio/MusicGenModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ private Tensor<T> GenerateMusicLatent(
}

// Initialize random latent
var rng = seed.HasValue ? RandomHelper.CreateSeededRandom(seed.Value) : RandomGenerator;
var rng = CreateInferenceRng(seed);
var latent = SampleNoiseTensor(latentShape, rng);

// Set up scheduler
Expand Down Expand Up @@ -712,7 +712,7 @@ private Tensor<T> GenerateContinuationLatent(
}

// Initialize with partial noise (more structure from prompt)
var rng = seed.HasValue ? RandomHelper.CreateSeededRandom(seed.Value) : RandomGenerator;
var rng = CreateInferenceRng(seed);
var noise = SampleNoiseTensor(latentShape, rng);

// Blend prompt latent into initial state
Expand Down
4 changes: 2 additions & 2 deletions src/Diffusion/Audio/RiffusionModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ private Tensor<T> GenerateSpectrogramInternal(
var latentShape = new[] { 1, RIFF_LATENT_CHANNELS, latentHeight, latentWidth };

// Initialize noise
var rng = seed.HasValue ? RandomHelper.CreateSeededRandom(seed.Value) : RandomGenerator;
var rng = CreateInferenceRng(seed);
var latents = SampleNoiseTensor(latentShape, rng);

// Set up scheduler
Expand Down Expand Up @@ -459,7 +459,7 @@ public virtual Tensor<T> InterpolateStyles(
var latentShape = new[] { 1, RIFF_LATENT_CHANNELS, latentHeight, latentWidth };

// Initialize noise
var rng = seed.HasValue ? RandomHelper.CreateSeededRandom(seed.Value) : RandomGenerator;
var rng = CreateInferenceRng(seed);
var latents = SampleNoiseTensor(latentShape, rng);

var effectiveGuidanceScale = guidanceScale ?? GuidanceScale;
Expand Down
8 changes: 4 additions & 4 deletions src/Diffusion/AudioDiffusionModelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public virtual Tensor<T> GenerateFromText(
var latentShape = new[] { 1, LatentChannels, MelChannels / VAE.DownsampleFactor, latentTimeFrames };

// Generate initial noise
var rng = seed.HasValue ? RandomHelper.CreateSeededRandom(seed.Value) : RandomGenerator;
var rng = CreateInferenceRng(seed);
var latents = DiffusionNoiseHelper<T>.SampleGaussian(latentShape, rng);

// Set up scheduler
Expand Down Expand Up @@ -257,7 +257,7 @@ public virtual Tensor<T> TextToSpeech(
var latentShape = new[] { 1, LatentChannels, MelChannels / VAE.DownsampleFactor, latentTimeFrames };

// Generate initial noise
var rng = seed.HasValue ? RandomHelper.CreateSeededRandom(seed.Value) : RandomGenerator;
var rng = CreateInferenceRng(seed);
var latents = DiffusionNoiseHelper<T>.SampleGaussian(latentShape, rng);

// Set up scheduler
Expand Down Expand Up @@ -331,7 +331,7 @@ public virtual Tensor<T> AudioToAudio(
var startTimestep = Scheduler.Timesteps.Skip(startStep).First();

// Add noise to latents at starting timestep
var rng = seed.HasValue ? RandomHelper.CreateSeededRandom(seed.Value) : RandomGenerator;
var rng = CreateInferenceRng(seed);
var noise = DiffusionNoiseHelper<T>.SampleGaussian(latentShape, rng);
var noisyLatents = Scheduler.AddNoise(latents.ToVector(), noise.ToVector(), startTimestep);
latents = new Tensor<T>(latentShape, noisyLatents);
Expand Down Expand Up @@ -388,7 +388,7 @@ public virtual Tensor<T> ContinueAudio(
var extensionShape = new[] { inputShape[0], inputShape[1], inputShape[2], extensionLatentFrames };

// Generate noise for extension
var rng = seed.HasValue ? RandomHelper.CreateSeededRandom(seed.Value) : RandomGenerator;
var rng = CreateInferenceRng(seed);
var extensionLatents = DiffusionNoiseHelper<T>.SampleGaussian(extensionShape, rng);

// Get conditioning from end of input
Expand Down
4 changes: 3 additions & 1 deletion src/Diffusion/Control/ControlARModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ public override void SetParameters(Vector<T> parameters)
public override IDiffusionModel<T> Clone()
{
var clone = new ControlARModel<T>(controlType: _controlType, conditioner: _conditioner, seed: RandomGenerator.Next());
clone.SetParameters(GetParameters());
// Copy-on-write: share weight tensors with the clone (O(1)-until-write) via the global helper;
// fall back to the eager flat copy only if the trainable-layer structure doesn't line up 1:1.
if (!clone.TryShareParametersFrom(this)) clone.SetParameters(GetParameters());
return clone;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Diffusion/Control/ControlNeXtModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public override void SetParameters(Vector<T> parameters)
public override IDiffusionModel<T> Clone()
{
var clone = new ControlNeXtModel<T>(controlType: _controlType, conditioner: _conditioner, seed: RandomGenerator.Next());
clone.SetParameters(GetParameters());
if (!clone.TryShareParametersFrom(this)) clone.SetParameters(GetParameters());
return clone;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Diffusion/Control/ControlNetInpaintingModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public override void SetParameters(Vector<T> parameters)
public override IDiffusionModel<T> Clone()
{
var clone = new ControlNetInpaintingModel<T>(controlType: _controlType, conditioner: _conditioner, seed: RandomGenerator.Next());
clone.SetParameters(GetParameters());
if (!clone.TryShareParametersFrom(this)) clone.SetParameters(GetParameters());
return clone;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Diffusion/Control/ControlNetLiteModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public override void SetParameters(Vector<T> parameters)
public override IDiffusionModel<T> Clone()
{
var clone = new ControlNetLiteModel<T>(controlType: _controlType, conditioner: _conditioner, seed: RandomGenerator.Next());
clone.SetParameters(GetParameters());
if (!clone.TryShareParametersFrom(this)) clone.SetParameters(GetParameters());
return clone;
}

Expand Down
6 changes: 3 additions & 3 deletions src/Diffusion/Control/ControlNetModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ public virtual Tensor<T> GenerateWithControl(
var latentShape = new[] { 1, CN_LATENT_CHANNELS, latentHeight, latentWidth };

// Initialize noise
var rng = seed.HasValue ? RandomHelper.CreateSeededRandom(seed.Value) : RandomGenerator;
var rng = CreateInferenceRng(seed);
var latents = SampleNoiseTensor(latentShape, rng);

// Set up scheduler
Expand Down Expand Up @@ -552,7 +552,7 @@ private Tensor<T> GenerateWithControlFeatures(
var latentShape = new[] { 1, CN_LATENT_CHANNELS, latentHeight, latentWidth };

// Initialize noise
var rng = seed.HasValue ? RandomHelper.CreateSeededRandom(seed.Value) : RandomGenerator;
var rng = CreateInferenceRng(seed);
var latents = SampleNoiseTensor(latentShape, rng);

// Set up scheduler
Expand Down Expand Up @@ -698,7 +698,7 @@ public override IDiffusionModel<T> Clone()
clone.GetOrCreateEncoder(controlType);
}

clone.SetParameters(GetParameters());
if (!clone.TryShareParametersFrom(this)) clone.SetParameters(GetParameters());
clone.ConditioningStrength = _conditioningStrength;

return clone;
Expand Down
4 changes: 3 additions & 1 deletion src/Diffusion/Control/ControlNetPlusPlusFluxModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ public override IDiffusionModel<T> Clone()
{
var clone = new ControlNetPlusPlusFluxModel<T>(
controlType: _controlType, conditioner: _conditioner, rewardWeight: _rewardWeight, seed: RandomGenerator.Next());
clone.SetParameters(GetParameters());
// #1624: O(1)-until-write copy-on-write parameter share (avoids the full-model flatten copy that
// OOMs the 16 GB runner). Falls back to the flat copy if the structure doesn't match 1:1.
if (!clone.TryShareParametersFrom(this)) clone.SetParameters(GetParameters());
return clone;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Diffusion/Control/ControlNetPlusPlusModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public override IDiffusionModel<T> Clone()
conditioner: _conditioner,
rewardWeight: _rewardWeight,
seed: RandomGenerator.Next());
clone.SetParameters(GetParameters());
if (!clone.TryShareParametersFrom(this)) clone.SetParameters(GetParameters());
return clone;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Diffusion/Control/ControlNetSD3Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public override IDiffusionModel<T> Clone()
controlType: _controlType,
conditioner: _conditioner,
seed: RandomGenerator.Next());
clone.SetParameters(GetParameters());
if (!clone.TryShareParametersFrom(this)) clone.SetParameters(GetParameters());
return clone;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Diffusion/Control/ControlNetTileModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public override void SetParameters(Vector<T> parameters)
public override IDiffusionModel<T> Clone()
{
var clone = new ControlNetTileModel<T>(conditioner: _conditioner, seed: RandomGenerator.Next());
clone.SetParameters(GetParameters());
if (!clone.TryShareParametersFrom(this)) clone.SetParameters(GetParameters());
return clone;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Diffusion/Control/ControlNetUnionProModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public override IDiffusionModel<T> Clone()
conditioner: _conditioner,
supportedTypes: _supportedTypes,
seed: RandomGenerator.Next());
clone.SetParameters(GetParameters());
if (!clone.TryShareParametersFrom(this)) clone.SetParameters(GetParameters());
return clone;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Diffusion/Control/IPAdapterFaceIDPlusModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ private static void AddParams(List<T> allParams, Vector<T> p)
public override IDiffusionModel<T> Clone()
{
var clone = new IPAdapterFaceIDPlusModel<T>(conditioner: _conditioner, faceIdScale: _faceIdScale, seed: RandomGenerator.Next());
clone.SetParameters(GetParameters());
if (!clone.TryShareParametersFrom(this)) clone.SetParameters(GetParameters());
return clone;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Diffusion/Control/IPAdapterModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ private Tensor<T> GenerateWithEmbedding(
var latentShape = new[] { 1, IPA_LATENT_CHANNELS, latentHeight, latentWidth };

// Initialize noise
var rng = seed.HasValue ? RandomHelper.CreateSeededRandom(seed.Value) : RandomGenerator;
var rng = CreateInferenceRng(seed);
var latents = SampleNoiseTensor(latentShape, rng);

// Set up scheduler
Expand Down Expand Up @@ -567,7 +567,7 @@ public override IDiffusionModel<T> Clone()
conditioner: _conditioner,
seed: RandomGenerator.Next());

clone.SetParameters(GetParameters());
if (!clone.TryShareParametersFrom(this)) clone.SetParameters(GetParameters());
clone.ImagePromptWeight = _imagePromptWeight;

return clone;
Expand Down
2 changes: 1 addition & 1 deletion src/Diffusion/Control/IPAdapterPlusModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public override IDiffusionModel<T> Clone()
conditioner: _conditioner,
ipAdapterScale: _ipAdapterScale,
seed: RandomGenerator.Next());
clone.SetParameters(GetParameters());
if (!clone.TryShareParametersFrom(this)) clone.SetParameters(GetParameters());
return clone;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Diffusion/Control/ReferenceOnlyModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public override void SetParameters(Vector<T> parameters)
public override IDiffusionModel<T> Clone()
{
var clone = new ReferenceOnlyModel<T>(conditioner: _conditioner, referenceWeight: _referenceWeight, seed: RandomGenerator.Next());
clone.SetParameters(GetParameters());
if (!clone.TryShareParametersFrom(this)) clone.SetParameters(GetParameters());
return clone;
}

Expand Down
Loading
Loading