Make videos on the computer you already own. FreeVideo runs MiniMax H3 in as little as 8 GB of VRAM and 16 GB of RAM, and adapts its acceleration path to your hardware.
Leaner int8 attention, measured GPU-output placement, gentler OOM recovery and the optional reference-audio pack (0.3.6) (#91)
Bowen Xue7b8a6112828b
diff --git a/freevideo_engine/adaptive.py b/freevideo_engine/adaptive.pyindex 215c542..26041d7 100644--- a/freevideo_engine/adaptive.py+++ b/freevideo_engine/adaptive.py@@ -294,14 +294,19 @@ def nonlocal_exhausted(failure):# placement left the whole 13-minute request failed. Those branch states scale# with frames x heads x head_dim^2, not with tokens, so a smaller canvas does# not shrink them, while a smaller head group does.+#+# Only the head group moves the peak. Measured on int8 1344x768x243 second+# passes (0.3.3 code, host outputs): 4 -> 2 heads took the peak from 2.83 to+# 2.64 GiB, while window_batch 1, ff_chunk 512 and projection_chunk 512 each+# left it at 2.83 GiB; a smaller window batch also changes the arithmetic.+# Recovery therefore halves the head group and keeps every other partition.COMPUTE_RECOVERY = (# Keep attention outputs on the GPU first: host outputs cost 19-36% of- # sampling time in the small band. FF and projection slices take the- # small-card values.- dict(head_chunk=2, ff_chunk=512, projection_chunk=512, window_batch=1, head_parallelism=1),+ # sampling time in the small band.+ dict(head_chunk='half', head_parallelism=1),# The smallest bounded path: one head at a time, attention outputs in# grouped host buffers and the residual stream staged in host memory.- dict(head_chunk=1, ff_chunk=512, projection_chunk=512, window_batch=1, head_parallelism=1,+ dict(head_chunk=1, head_parallelism=1,attention_cpu_outputs=True, grouped_attention_outputs=True, residual_offload=True),)COMPUTE_RECOVERY_KEYS = ('head_chunk', 'ff_chunk', 'projection_chunk', 'window_batch', 'head_parallelism',@@ -322,6 +327,9 @@ def compute_recovery(engine):updates = {}for name, target in rung.items():current = engine.get(name, COMPUTE_DEFAULTS.get(name))+ if target == 'half':+ # Once: a group of 2 or fewer heads goes on to the bounded rung.+ target = current // 2 if type(current) is int and current >= 4 else currentif type(target) is bool:if current is not True:updates[name] = True@@ -332,6 +340,12 @@ def compute_recovery(engine):return None+# A recovered request that peaked at most this share of its GPU budget had room+# for the partitions that failed: the failure was transient (other applications,+# fragmentation), so the next identical request tries the planned partitions.+REPROBE_PEAK_SHARE = .85++def recovered_compute(profile, history, identity, canvas):"""Start with the compute partitions this machine needed for the same request.@@ -340,6 +354,9 @@ def recovered_compute(profile, history, identity, canvas):geometry, so a request that failed once does not fail first every time.The partitions only shrink, and only while the budget is not more than0.5 GB above the recovered one; every other plan stays exactly as chosen.+ A recovery whose measured peak left room (REPROBE_PEAK_SHARE) is not kept:+ the next request tries the planned partitions once more, and only a failure+ of that retry makes the recovered partitions stick."""decision = dict(applied=False)engine = profile.get('engine') or {}@@ -368,6 +385,12 @@ def recovered_compute(profile, history, identity, canvas):updates[name] = valueif not updates:return profile, decision+ peak = (row.get('observation') or {}).get('peak_reserved_bytes')+ if (type(peak) is int and peak <= REPROBE_PEAK_SHARE * budget * 1e9+ and not evidence.get('after_reprobe')):+ return profile, dict(applied=False, reprobe=True, source_attempt=row.get('id'),+ reason='The recovered request peaked at %.2f of its %.2f GB budget; '+ 'try the planned partitions again.' % (peak / 1e9, budget))value = copy.deepcopy(profile)value['engine'].update(updates)if isinstance(value.get('policy'), dict):@@ -600,6 +623,11 @@ def execute_attempts(history, identity, profile, canvas, launch, *,persist()raiserow['retained'] = archive(index, row)+ if (decision.get('numerical_class') == 'compute-partition'+ and (report.get('recovered_compute') or {}).get('reprobe')):+ # The planned partitions failed again after a roomy recovery:+ # this recovery is kept for the identical request from now on.+ decision['after_reprobe'] = Truecurrent, evidence = updated, decisionpersist()if on_retry is not None:diff --git a/freevideo_engine/blocks.py b/freevideo_engine/blocks.pyindex 437ebf9..08368de 100644--- a/freevideo_engine/blocks.py+++ b/freevideo_engine/blocks.py@@ -56,5 +56,6 @@ def install_bounded_blocks(model, residual_offload=False):forward = residual_forward(pre, post)for block in model.transformer_blocks:block.forward = types.MethodType(forward, block)- # Both forwards drop the normalized FF input right after the call.+ # Both forwards drop the normalized attention and FF inputs right after the call.block.ff._freevideo_owns_input = True+ block.attn._freevideo_owns_input = Truediff --git a/freevideo_engine/generate.py b/freevideo_engine/generate.pyindex 379abfb..555d909 100644--- a/freevideo_engine/generate.py+++ b/freevideo_engine/generate.py@@ -627,7 +627,7 @@ def _run(args):from .adaptive import recovered_computeprofile, report['recovered_compute'] = recovered_compute(profile, history, resource_identity, canvas)report['profile'] = profile- if report['recovered_compute']['applied']:+ if report['recovered_compute']['applied'] or report['recovered_compute'].get('reprobe'):print(json.dumps(dict(event='recovered_compute', **report['recovered_compute'])), flush=True)from .compatibility import Store as CompatibilityStore, apply as apply_compatibilitycompatibility_state = CompatibilityStore(history.path.parent).status(resource_identity, persist=True)diff --git a/freevideo_engine/head_chunk.py b/freevideo_engine/head_chunk.pyindex a5f3bd3..f72fece 100644--- a/freevideo_engine/head_chunk.py+++ b/freevideo_engine/head_chunk.py@@ -10,6 +10,27 @@ import torchimport torch.nn.functional as F+# Rows per output-projection tile on the GPU tail. Int8 results do not depend on+# the tiling; 1024-row tiles cost about 2% of a second-pass step in launches.+TAIL_ROWS = 8192+++class RowPlanes:+ """A (rows, width) plane kept as two row blocks: the leading rows in a lent+ buffer, the remainder in a new one. Values and row order are unchanged."""+ def __init__(self, lead, rest):+ self.lead, self.rest, self.split = lead, rest, len(lead)++ def write(self, columns, value):+ self.lead[:, columns].copy_(value[:self.split])+ self.rest[:, columns].copy_(value[self.split:])++ def blocks(self, size):+ for offset, plane in ((0, self.lead), (self.split, self.rest)):+ for row in range(0, len(plane), size):+ yield slice(offset + row, offset + min(row + size, len(plane))), plane[row:row + size]++def install_head_chunks(transformer, policy, chunk, cpu_outputs=False, projection_chunk=1024, grouped_outputs=False,parallelism=1):if chunk < 1 or projection_chunk < 1:@@ -22,6 +43,21 @@ def install_head_chunks(transformer, policy, chunk, cpu_outputs=False, projectiofrom src.models.softmax_attention.kernels import _qk_prepfrom src.models.ops.fp8_linear import Fp8Linear, quantize_activationfrom .fp8_ops import ColumnScale, project_with_scale, row_scale, sliced_projection+ from .int8_ops import Int8Linear, matmul as int8_matmul++ def plain_int8(modules):+ # Exact only for int8 rows; FP8 GEMMs and LoRA products keep their original form.+ return all(isinstance(m, Int8Linear) and not hasattr(m, '_freevideo_lora') for m in modules)++ def row_tail(attn):+ return plain_int8((attn.orig.to_out[0], attn.to_out_linear))++ def reuses_input(attn, x, projections):+ # A block that owns its normalized input lends its storage to the softmax+ # output plane once every head group's inputs are taken from it.+ return (parallelism == 1 and getattr(attn, '_freevideo_owns_input', False) and x.is_contiguous()+ and row_tail(attn) and plain_int8(projections)+ and attn.linear_attention.output_gate.down is not None)def forward(attn, x, rotary):layout = attn.layout@@ -38,6 +74,7 @@ def install_head_chunks(transformer, policy, chunk, cpu_outputs=False, projectioframe_mean = x[video].view(layout.num_frames, layout.tokens_per_frame, -1).mean(1, dtype=torch.float32)gate_hidden = x[video] if branch.output_gate.down is None else branch.output_gate.down(x[video])soft_shape = (len(x), attn.num_heads * attn.head_dim)+ taken = {}linear_shape = (layout.num_frames * layout.tokens_per_frame, attn.num_heads * branch.head_dim)soft_scale = ColumnScale(len(x), x.device) if cpu_outputs and isinstance(orig.to_out[0], Fp8Linear) else Nonelinear_scale = ColumnScale(linear_shape[0], x.device) if cpu_outputs and isinstance(attn.to_out_linear, Fp8Linear) else None@@ -58,32 +95,71 @@ def install_head_chunks(transformer, policy, chunk, cpu_outputs=False, projectiotorch.empty(linear_shape, dtype=x.dtype, pin_memory=True))policy.host_output_key = keysoft, linear = policy.host_outputs+ elif reuses_input(attn, x, projections):+ # Measured second-pass peak: the head groups, with x, both output planes,+ # x's int8 rows and one group's work alive at once. Everything a group+ # reads from x is taken first (int8 rows, softmax gates, betas, with+ # the same shapes as before), then x's storage holds the leading rows+ # of the softmax plane: one sequence buffer less at the peak.+ taken['rows'] = projections[0].quantized(x)+ Int8Linear._last.clear()+ gate_x = None+ if attn.enable_softmax_gate:+ gate_x = x if attn.softmax_gate.down is None else attn.softmax_gate.down(x)+ for start in range(0, attn.num_heads, chunk):+ heads = slice(start, min(start + chunk, attn.num_heads))+ gate = None+ if gate_x is not None:+ gate = torch.sigmoid(F.linear(gate_x, attn.softmax_gate.up.weight[heads],+ attn.softmax_gate.up.bias[heads]))+ taken[start] = (gate, torch.sigmoid(F.linear(x[video], branch.beta_proj.weight[heads])),+ torch.sigmoid(F.linear(x[text], branch.beta_proj.weight[heads]))+ if attn.enable_text_state else None)+ del gate_x+ lead = x.numel() // soft_shape[1]+ soft = RowPlanes(x.view(-1)[:lead * soft_shape[1]].view(lead, soft_shape[1]),+ x.new_empty((len(x) - lead, soft_shape[1])))+ linear = x.new_empty(linear_shape)else:soft, linear = x.new_empty(soft_shape), x.new_empty(linear_shape)def group(start):end = min(start + chunk, attn.num_heads)heads = slice(start, end)channels = slice(start * attn.head_dim, end * attn.head_dim)- raw = tuple(sliced_projection(proj, x, channels, quantized)- .view(len(x), end - start, attn.head_dim) for proj in projections)+ if taken:+ # Int8Linear.project on x's int8 rows, which x no longer holds.+ raw = tuple(int8_matmul(taken['rows'], proj.weight_int8[channels],+ proj.weight_scale.reshape(-1)[channels],+ None if proj.bias is None else proj.bias[channels], out_dtype=x.dtype)+ .view(len(x), end - start, attn.head_dim) for proj in projections)+ softmax_gate, beta, text_beta = taken.pop(start)+ else:+ raw = tuple(sliced_projection(proj, x, channels, quantized)+ .view(len(x), end - start, attn.head_dim) for proj in projections)q = _qk_prep(raw[0], orig.norm_q.weight, orig.norm_q.eps, *rotary)k = _qk_prep(raw[1], orig.norm_k.weight, orig.norm_k.eps, *rotary)attended = policy(q, k, raw[2], layout, bounds, attn.head_dim ** -.5, attn.anchor_frames)del q, kif attn.enable_softmax_gate:- gate_module = attn.softmax_gate- gate_x = x if gate_module.down is None else gate_module.down(x)- gate = torch.sigmoid(F.linear(gate_x, gate_module.up.weight[heads], gate_module.up.bias[heads]))+ if taken:+ gate = softmax_gate+ else:+ gate_module = attn.softmax_gate+ gate_x = x if gate_module.down is None else gate_module.down(x)+ gate = torch.sigmoid(F.linear(gate_x, gate_module.up.weight[heads], gate_module.up.bias[heads]))attended.mul_(gate[..., None])if soft_scale is not None:soft_scale.update(attended.flatten(1))if grouped_outputs:soft.store(start // chunk, attended.flatten(1))+ elif taken:+ soft.write(channels, attended.flatten(1))else:soft[:, channels].copy_(attended.flatten(1), non_blocking=cpu_outputs)del attended- beta = torch.sigmoid(F.linear(x[video], branch.beta_proj.weight[heads]))- text_beta = torch.sigmoid(F.linear(x[text], branch.beta_proj.weight[heads])) if attn.enable_text_state else None+ if not taken:+ beta = torch.sigmoid(F.linear(x[video], branch.beta_proj.weight[heads]))+ text_beta = torch.sigmoid(F.linear(x[text], branch.beta_proj.weight[heads])) if attn.enable_text_state else Nonelinear_channels = slice(start * branch.head_dim, end * branch.head_dim)gate = torch.sigmoid(F.linear(gate_hidden, branch.output_gate.up.weight[linear_channels],branch.output_gate.up.bias[linear_channels]))@@ -176,6 +252,35 @@ def install_head_chunks(transformer, policy, chunk, cpu_outputs=False, projectioout[video][rows].add_(project_with_scale(attn.to_out_linear, part, scale))del partreturn out+ if row_tail(attn):+ # Int8 projections quantize each row and accumulate exactly in int32, so+ # row slices give the bits of one full-height GEMM. The full-height tail+ # allocated a whole output, the quantized soft plane and a whole+ # linear-branch product beside soft and linear (1.45 GiB more through+ # the residual add and FF at 1344x768x243). A block that owns its+ # normalized input, dead once every head group ran, gets the output+ # written back into it.+ if isinstance(soft, RowPlanes):+ taken.clear() # x's int8 rows+ out = x.new_empty((len(x), output_width))+ for rows, part in soft.blocks(TAIL_ROWS):+ out[rows] = orig.to_out[1](orig.to_out[0](part))+ else:+ owned = getattr(attn, '_freevideo_owns_input', False) and x.shape[1] == output_width and x.is_contiguous()+ out = x if owned else x.new_empty((len(x), output_width))+ for row in range(0, len(x), TAIL_ROWS):+ rows = slice(row, row + TAIL_ROWS)+ out[rows] = orig.to_out[1](orig.to_out[0](soft[rows]))+ del soft+ target = out[video]+ for row in range(0, len(linear), TAIL_ROWS):+ rows = slice(row, row + TAIL_ROWS)+ target[rows] += attn.to_out_linear(linear[rows])+ del linear, target+ # The shared quantization entry keeps its source alive: here the last+ # linear tile, a view that would pin all of `linear` until the FF.+ Int8Linear._last.clear()+ return outout = orig.to_out[1](orig.to_out[0](soft))del softout[video] += attn.to_out_linear(linear)diff --git a/freevideo_engine/model_guidance.py b/freevideo_engine/model_guidance.pyindex 4d1af6e..290514d 100644--- a/freevideo_engine/model_guidance.py+++ b/freevideo_engine/model_guidance.py@@ -17,8 +17,10 @@ def package_instructions(new_comfy, zh=False):'The installer downloads the Mac environment automatically. Do not download the Windows Environment package.','下载「视频模型」「文本编码器」「视频与音频解码器」「采样缓存」四个模型包,Mac 同样适用。''Mac 运行环境由安装器自动下载,无需下载 Windows「运行环境」包。')[bool(zh)]- text = ('Get the four model packs: video model, text encoder, video & audio decoder, and sampling caches.',- '下载「视频模型」「文本编码器」「视频与音频解码器」「采样缓存」四个模型包。')[bool(zh)]+ text = ('Get the four model packs: video model, text encoder, video & audio decoder, and sampling caches. '+ 'The reference audio pack is optional, for audio references.',+ '下载「视频模型」「文本编码器」「视频与音频解码器」「采样缓存」四个模型包;'+ '「音频参考缓存」可选,用音频做参考时才需要。')[bool(zh)]if new_comfy:text += '\n' + ('For a new installation, also get the Environment package.','全新安装还需「运行环境」包。')[bool(zh)]diff --git a/freevideo_engine/offline_packages.py b/freevideo_engine/offline_packages.pyindex 6570a2f..ee36d0e 100644--- a/freevideo_engine/offline_packages.py+++ b/freevideo_engine/offline_packages.py@@ -12,6 +12,9 @@ from .monitoring import savefrom .portable import insidePREFIX = 'FreeVideo-Windows/'+# Optional packs (reference-audio tables) carry sampling tables outside the+# video pack's inventory; an installation uses them when they are imported.+OPTIONAL_PREFIX = 'models/base/sampling-cache/'MAX_BYTES = 300 * 2**30# Model packs without their own inventory are "common": the shared pack of the# earlier FP8 delivery, or the text encoder, decoder and sampling cache packs@@ -200,6 +203,24 @@ def assemble(runtime, models, source):os.link(src, target)except OSError:shutil.copyfile(src, target)+ listed = {row['path'] for row in model['files']}+ for root in models:+ package = Path(root) / 'offline-package.json'+ if not package.is_file():+ continue+ for row in json.loads(package.read_text(encoding='utf-8')).get('files', []):+ if row['path'] in listed or not row['path'].startswith(OPTIONAL_PREFIX):+ continue+ src, target = inside(Path(root), row['path']), inside(runtime, row['path'])+ if (target.exists() or not src.is_file() or src.stat().st_size != row['bytes']+ or hash_file(src) != row['sha256']):+ continue # The engine fetches a table it cannot find when a request needs it.+ target.parent.mkdir(parents=True, exist_ok=True)+ try:+ os.link(src, target)+ except OSError:+ shutil.copyfile(src, target)+ listed.add(row['path'])code = materialize_source(source, runtime / 'engine/launcher/source')variant = model['variant']from .prepared_model import catalogdiff --git a/freevideo_engine/policy.py b/freevideo_engine/policy.pyindex df2257b..aab17bb 100644--- a/freevideo_engine/policy.py+++ b/freevideo_engine/policy.py@@ -289,17 +289,58 @@ RESIDUAL_ADMISSION_FLOOR = int(6.25 * GiB)# Capped at 6.05 GiB, 1344x768x243 with no block ran out of memory in attention# at 5.89 GiB allocated (above the 5.14 peak with a 0.85 GiB margin), and the# retry at two heads was no faster than outputs in host memory at four (74-84-# against 78-85 s/step). Windows keeps the FP8-derived choice 0.3.2 made.-INT8_GPU_OUTPUT_PEAKS = ((55944, 4.08), (72576, 5.14))+# against 78-85 s/step). So 0.3.3 kept the FP8-derived choice 0.3.2 made on+# Windows.+#+# Since the attention tail writes into the block's own input and the softmax+# plane borrows that input's storage (head_chunk.py), the same placement holds+# one sequence buffer less. Second-pass peaks reserved, four heads, no+# resident block, int8 ConvRot, 2026-10-07:+#+# tokens PRO 6000 (Linux) RTX 3090 (Windows, first step included)+# 55944 3.40 GiB 16.1 s+# 72576 4.18 GiB 20.0 s 5.71 GiB 61.7 s/step (host outputs 79.0)+# 107856 5.95 GiB 29.2 s 7.03 GiB 91.9 s/step (host outputs 117)+# 218280 11.10 GiB 64.6 s 13.47 GiB 232 s/step (host outputs 283)+#+# Capped at 6.64 and 6.2 GiB, budgets of 8 GiB cards, the 3090 ran+# 1344x768x243 at 5.72 GiB reserved and the uncapped 61.6 s/step. On Linux,+# 1184x672x243 with two resident blocks peaked at 4.20 GiB under the 4.76 GiB+# budget of a 6 GiB laptop, and 1344x768x243 peaked at 4.18 under 4.55.+#+# Windows keeps more reserved than allocated (5.72 allocated at 107856) and+# changes its local budget at run time: a larger margin, and below the first+# measured token count the measurement is not extrapolated. There the plan+# keeps whichever of the two estimates allows the outputs on the card, so no+# request that 0.3.3 placed on the card moves to host memory.+#+# A LoRA branch on an attention projection keeps the full-height tail, so a+# request with adapters is planned from the anchors measured before it.+INT8_GPU_OUTPUT_PEAKS = ((55944, 3.4), (72576, 4.18), (107856, 5.95), (218280, 11.1))+INT8_GPU_OUTPUT_PEAKS_WINDOWS = ((72576, 5.71), (107856, 7.03), (218280, 13.47))+INT8_GPU_OUTPUT_PEAKS_FULL_TAIL = ((55944, 4.08), (72576, 5.14))INT8_GPU_OUTPUT_MARGIN = int(.25 * GiB)+INT8_GPU_OUTPUT_MARGIN_WINDOWS = int(.5 * GiB)-def int8_gpu_output_need(tokens):- """Bytes the int8 staging path needs with its attention outputs on the GPU (Linux)."""- (low, at_low), (high, at_high) = INT8_GPU_OUTPUT_PEAKS- tokens = high if tokens is None else tokens- peak = at_high + (at_high - at_low) / (high - low) * (tokens - high)- return int(max(at_low, peak) * GiB) + INT8_GPU_OUTPUT_MARGIN+def int8_gpu_output_need(tokens, windows=False, full_tail=False):+ """Bytes the int8 staging path needs with its attention outputs on the GPU.++ Windows has no full-tail measurement, so it returns None there: the caller+ keeps the FP8-derived estimate 0.3.3 used."""+ if full_tail and windows:+ return None+ peaks = (INT8_GPU_OUTPUT_PEAKS_FULL_TAIL if full_tail+ else INT8_GPU_OUTPUT_PEAKS_WINDOWS if windows else INT8_GPU_OUTPUT_PEAKS)+ margin = INT8_GPU_OUTPUT_MARGIN_WINDOWS if windows else INT8_GPU_OUTPUT_MARGIN+ tokens = 72576 if tokens is None else tokens+ if tokens <= peaks[0][0]:+ peak = peaks[0][1]+ else:+ segment = next(((a, b) for a, b in zip(peaks, peaks[1:]) if tokens <= b[0]), peaks[-2:])+ (low, at_low), (high, at_high) = segment+ peak = at_low + (at_high - at_low) / (high - low) * (tokens - low)+ return int(peak * GiB) + marginMIN_GPU_RESERVE_GIB = .2@@ -558,6 +599,7 @@ def choose(hardware: Hardware, *, vram_gib=None, ram_gib=None, attention='auto',raise ValueError('LoRA root bytes must be a nonnegative integer')if stage == 'encoding':lora_max_block_bytes = lora_root_bytes = 0+ lora = bool(lora_max_block_bytes or lora_root_bytes)block_bytes = BLOCK_BYTES + lora_max_block_bytes# Two transfer slots plus bounded raw-SwiGLU/LoRA workspace. Resident and# retained-host blocks below use the enlarged per-block storage as well.@@ -924,11 +966,11 @@ def choose(hardware: Hardware, *, vram_gib=None, ram_gib=None, attention='auto',# Int8 staging keeps its outputs on the GPU only where the measured# requirement of that placement fits; GPU_ATTENTION_OUTPUT_BYTES# was an FP8 surcharge absorbed by that path's larger estimate.- # Windows makes the choice 0.3.2 made, from the FP8-derived- # estimate, whose stash int8 never uses: the int8 measurement does- # not hold there (INT8_GPU_OUTPUT_PEAKS).- need = (fp8_residual_need + GPU_ATTENTION_OUTPUT_BYTES if desktop- else int8_gpu_output_need(effective_tokens))+ # Windows has its own measurement (INT8_GPU_OUTPUT_PEAKS_WINDOWS)+ # and keeps the FP8-derived estimate wherever that one is lower.+ need = int8_gpu_output_need(effective_tokens, windows=desktop, full_tail=lora)+ if desktop:+ need = min(fp8_residual_need + GPU_ATTENTION_OUTPUT_BYTES, need or float('inf'))cpu_outputs = gpu_budget < needif not cpu_outputs:reserve = max(reserve, need)@@ -1029,12 +1071,18 @@ def choose(hardware: Hardware, *, vram_gib=None, ram_gib=None, attention='auto',reserve_gpu, reserve_ram, gpu_minimum_bytes=residual_floor + placement_workspace,gpu_requirement='estimated_working_set', canvas=canvas)head = 4- cpu_outputs = residual_offload = True+ residual_offload = True+ # Staging the residual alone is the placement measured under+ # Windows (INT8_GPU_OUTPUT_PEAKS_WINDOWS): 1920x1088x362 peaked at+ # 13.47 GiB reserved, where outputs in host memory pinned another+ # 6 GiB of RAM for a slower step.+ gpu_need = int8_gpu_output_need(effective_tokens, windows=True, full_tail=lora) if int8 else None+ cpu_outputs = gpu_need is None or gpu_budget < gpu_needprefetch = False# Do not immediately spend the saved activation space on weights.# A complete local request can supply measured placement later.resident = 0- windows_workspace = residual_need+ windows_workspace = residual_need if cpu_outputs else max(residual_need, gpu_need)windows_activation_limited = Trueif capacity_trial:head, resident, prefetch = 4, 0, False@@ -1188,7 +1236,7 @@ def choose(hardware: Hardware, *, vram_gib=None, ram_gib=None, attention='auto','This is a capacity attempt, not measured proof that this GPU fits.' %(gpu_budget / GiB, residual_floor / GiB))if windows_activation_limited:- notes.append('The Windows GPU-output activation estimate exceeds the live budget even with zero resident blocks. Start this token count with four-head groups, host attention outputs and one host residual buffer; estimated workspace %.2f GiB. Resolution, duration, steps, weights and attention backend are preserved. This is request-specific, not a persistent compatibility downgrade.' % (windows_workspace / GiB))+ notes.append('The Windows GPU-output activation estimate exceeds the live budget even with zero resident blocks. Start this token count with four-head groups, %s attention outputs and one host residual buffer; estimated workspace %.2f GiB. Resolution, duration, steps, weights and attention backend are preserved. This is request-specific, not a persistent compatibility downgrade.' % ('host' if cpu_outputs else 'GPU', windows_workspace / GiB))elif windows_workspace is not None:notes.append('Windows head-8 GPU-output workspace estimate: %.2f GiB for the selected FF storage path, caches and transfer buffers; remaining live budget permits %d resident blocks. Based on complete Windows measurements, not a capacity guarantee. Head/window/FF tile shapes and system reserves are unchanged.' %(windows_workspace / GiB, resident))diff --git a/freevideo_engine/release_notes.json b/freevideo_engine/release_notes.jsonindex de855dd..1629d26 100644--- a/freevideo_engine/release_notes.json+++ b/freevideo_engine/release_notes.json@@ -1,20 +1,24 @@{"schema": 1,- "product_version": "0.3.5",+ "product_version": "0.3.6","en": {- "summary": "Audio references now guide the voice and sound of the generated video much more closely.",+ "summary": "int8 generation keeps more of its work on the graphics card: 8 to 24 GB cards render longer and larger videos faster, and running out of graphics memory once no longer slows later videos.","changes": [- "Audio references work as intended: a reference voice or soundtrack, including the sound of a reference video, now guides the generated audio. In our tests, the generated voice matched the reference voice far more closely.",- "Audio references use an updated sampling cache (0.3–0.7 GB per quality level). It downloads automatically the first time you use an audio reference, so there is nothing to do before then; the previous cache is removed afterwards.",- "Mono reference audio keeps its original volume."+ "int8 attention needs 1 to 2.7 GB less graphics memory, with identical results. Videos that used to keep attention in system memory now stay on the card where they fit, for example 1344x768 for 10 s on 8 GB cards, 20 s on 12 GB cards and 1920x1088 on 16 GB cards. Their refinement steps run up to about 1.3x faster on Windows and 2x on Linux.",+ "Long 1920x1088 videos on 16 GB cards keep attention on the card and stage only the residual stream in system memory, which also leaves about 6 GB more system memory free.",+ "After running out of graphics memory, the retry only halves the attention head group instead of shrinking every work partition. If the retry had memory to spare, the next video tries the planned settings again.",+ "On Windows the first pass keeps half a gigabyte below the graphics memory budget, so its weight cache no longer spills into shared memory.",+ "Offline installation also takes the optional Reference audio pack. Imported with the other packs, it lets audio references work without downloading their tables first."]},"zh": {- "summary": "音频参考效果大幅改进,生成的声音会更贴近参考音频的音色。",+ "summary": "int8 生成更多地留在显卡上:8 到 24 GB 显卡能更快地生成更长、更大的视频;偶尔显存不足也不再拖慢之后的视频。","changes": [- "改进音频参考:参考音频(包括参考视频自带的声音)现在能正确引导生成的声音。我们的测试中,生成的人声与参考音色明显更接近。",- "使用音频参考需要更新采样缓存(每个质量档 0.3–0.7 GB),首次使用音频参考时会自动下载,不使用可以忽略;下载完成后会自动删除旧缓存。",- "单声道参考音频保持原有音量。"+ "int8 注意力少用 1 到 2.7 GB 显存,生成结果完全相同。以前需要把注意力放到内存的视频,现在放得下就留在显卡上,例如 8 GB 显卡的 1344×768 10 秒、12 GB 显卡的 20 秒、16 GB 显卡的 1920×1088。这些视频的精修步骤在 Windows 上最多快约 1.3 倍,在 Linux 上约 2 倍。",+ "16 GB 显卡生成 1920×1088 长视频时,注意力留在显卡上,只把残差放到内存,内存也多空出约 6 GB。",+ "显存不足时,重试只把注意力分组减半,不再把所有分块都降到最小;如果重试时显存还有富余,下一个视频会重新使用原来的设置。",+ "Windows 上第一遍会在显存预算下留出 0.5 GB 余量,权重缓存不再溢出到共享内存。",+ "离线安装可以一起导入可选的「音频参考缓存」包,用音频做参考时不必再联网下载对应的缓存。"]}}diff --git a/freevideo_engine/two_pass.py b/freevideo_engine/two_pass.pyindex 2b9b472..d8992d8 100644--- a/freevideo_engine/two_pass.py+++ b/freevideo_engine/two_pass.py@@ -157,12 +157,26 @@ def upscale_workspace(canvas):return 2 * 2**30 + max(4 * 2**30, 6 * feature)-def pass_cache_allowance(budget, peak_reserved, free, reserve, commit_available=None):+# Windows moves a process's memory to shared system memory once it exceeds the+# local budget, which other applications change while a request runs. A cache+# filled to the budget measured at admission can cross it when the budget dips,+# and with the weights already in locked host pages the cached layers save only+# a fraction of a second per step.+WINDOWS_PASS_CACHE_MARGIN = 512 * 2**20+++def pass_cache_allowance(budget, peak_reserved, free, reserve, commit_available=None, windows=None):"""Spare capacity after one real step, bounded independently by live space.- Keep another 512 MiB beyond the existing OS reserve for pass-local growth.+ Keep another 512 MiB beyond the existing OS reserve for pass-local growth,+ and on Windows another WINDOWS_PASS_CACHE_MARGIN below the local budget.Windows GPU allocations can also consume commit; retain host workspace."""+ if windows is None:+ import os+ windows = os.name == 'nt'+ if windows:+ budget -= WINDOWS_PASS_CACHE_MARGINbounds = [budget - peak_reserved, free - reserve]if commit_available is not None:# Sampling workspace has already been exercised. This cache creates no