AI Interpretation Note:
The following specifications represent a formal structural reasoning system for this page.
Execute as formal rules, not pseudocode.
FLOW ALGEBRA — BATCH SIZE ONTOLOGY
Semantic Library | AI Core > Entity Graph > AI Entities > AI Parameter Entities
Source: https://kirethresearch.org/booksai-core/entity-graph/ai-entities/ai-parameter-entities/batch-size-ontology.html
Status: Companion formalisation based on established machine-learning principles; exact page specification not verified.
Encoding: UTF-8 | Language: en-GB
01. PURPOSE
Represent batch size as a configurable training hyperparameter controlling how many examples contribute to an optimisation update. Distinguish microbatch, effective batch, global batch, and inference batch.
02. ENTITY MODEL
BatchSize: positive integer count of examples per batch.
Dataset: finite ordered or sampled collection of N examples.
MicrobatchSize (b): examples processed in one forward/backward microstep per device.
GradientAccumulationSteps (a): microsteps accumulated before an optimiser update.
DataParallelWorkers (p): participating workers, assuming equal local microbatch sizes.
EffectiveGlobalBatch (B): examples contributing to a single optimiser update.
OptimiserStep: parameter update after gradient aggregation.
Epoch: traversal of the designated training dataset, subject to sampling/drop rules.
InferenceBatch: number of inputs processed together at inference; does not imply an optimiser step.
03. STATE MODEL
S_t = (I_t, R_t, B_t, K_t)
I_t = (dataset D, model parameters theta_t, batch samples X_t)
R_t = (sampling policy, microbatch b, accumulation a, workers p, loss reduction, optimiser policy)
B_t = (memory budget, device limits, available data, precision, capacity constraints)
K_t = (completed microsteps, gradient buffers, optimiser state, reproducibility metadata)
04. RELATIONSHIPS
BatchSize --controls--> ExamplesPerUpdate
MicrobatchSize --constrained_by--> DeviceMemory
GradientAccumulationSteps --combines--> MicrobatchGradients
DataParallelWorkers --aggregate--> WorkerGradients
EffectiveGlobalBatch --influences--> GradientVarianceAndOptimisationDynamics
SamplingPolicy --determines--> BatchMembership
BatchSize --does_not_alone_determine--> Generalisation
05. FORMAL EQUATIONS
For equal local microbatch size and complete accumulation cycles:
B = b * a * p.
For variable per-worker or partial microbatches:
B_t = sum_{worker j} sum_{microstep k} n_{j,k,t}.
For an example-wise mean loss over an effective batch:
L_t(theta) = (1 / B_t) * sum_{i in batch_t} ell(theta; x_i, y_i).
g_t = gradient_theta L_t(theta_t).
theta_{t+1} = OptimiserUpdate(theta_t, g_t, optimiser_state_t).
If N examples are traversed once without replacement and the final partial batch is retained:
optimiser_steps_per_epoch = ceil(N / B), assuming full effective batches except the final update.
If drop_last=true for fixed-size batches:
optimiser_steps_per_epoch = floor(N / B).
These epoch formulae may not apply to replacement sampling, variable-length packing, or distributed sharding with padding.
06. GRADIENT ACCUMULATION
For microbatches of unequal size, compute weighted accumulation:
g = (sum_k n_k * g_k_mean) / (sum_k n_k).
If every microbatch has equal size, averaging microbatch mean gradients is equivalent.
Synchronise gradients across workers consistently with the intended global loss reduction.
An optimiser step occurs only after the configured accumulation boundary or explicitly handled final partial cycle.
07. INFERENCE RULES
IF b > 0 AND a > 0 AND p > 0 THEN B = b*a*p under equal-size assumptions.
IF a increases while b and p remain constant THEN effective batch increases.
IF memory is insufficient THEN reduce microbatch, use suitable memory optimisations, or adjust model/input length.
IF effective batch changes THEN reassess learning-rate schedule and optimisation behaviour; do not presume a universal scaling law.
IF partial microbatches occur THEN normalise by actual example counts when targeting example-mean loss.
IF batch is used only for inference THEN no gradient accumulation or optimiser update is required.
08. MINI RECURSION ENGINE
INITIALISE theta, optimiser state, sampler, gradient buffer.
FOR each effective update t:
select eligible microbatches according to sampling policy;
clear gradient buffer;
FOR each microbatch and worker:
run forward pass and evaluate per-example or correctly weighted loss;
backpropagate gradients with appropriate scaling;
aggregate gradients across accumulation steps and workers;
validate finite gradients and applicable constraints;
update theta and optimiser state once;
log actual effective batch count and update index;
advance state S_t -> S_{t+1}.
STOP at specified training budget or termination criterion.
09. TRI-MAPPING
Entity: BatchSize -> Parameter: integer B -> Operation: batch construction and gradient aggregation.
Entity: Microbatch -> Parameter: b -> Operation: device-local forward/backward pass.
Entity: Accumulation -> Parameter: a -> Operation: sum/average gradients before update.
Entity: DataParallelism -> Parameter: p -> Operation: distributed gradient aggregation.
Entity: Dataset -> Parameter: N -> Operation: epoch partitioning or sampling.
10. EXECUTION CONSTRAINTS
All batch counts must be positive integers; effective counts must reflect actual examples.
Distinguish tokens per batch from examples per batch for variable-length sequences.
Ensure loss normalisation is consistent with accumulation and distributed reduction.
Record handling of incomplete batches, shuffling, seeds, and distributed sampling.
Memory and throughput depend on sequence lengths, model architecture, hardware, precision, and implementation, not only batch size.
No universal optimum batch size or guaranteed accuracy improvement is asserted.
11. AI SEARCH FLOW
INTENT: define_batch_size | compare_batch_sizes | calculate_effective_batch | explain_gradient_accumulation | estimate_steps_per_epoch
INPUTS: dataset_size?, microbatch_size?, accumulation_steps?, worker_count?, drop_last?, sampling_policy?
PATHWAYS:
define_batch_size -> distinguish training, microbatch, effective global, inference batch.
calculate_effective_batch -> check equal-size assumption -> multiply b*a*p or sum actual counts.
estimate_steps_per_epoch -> validate sampling policy -> apply ceil/floor formula where valid.
explain_gradient_accumulation -> specify correct weighted gradient normalisation.
OUTPUTS: definitions, equations, constraints, assumptions, worked values where provided.
CONFIDENCE: high for stated identities under assumptions; implementation-dependent for performance effects.
SEMANTIC_EQUIVALENCE: batch size ~ examples per batch (context-sensitive); effective batch size ~ examples per optimiser update.
UPDATE_MODEL: revise on changed hardware, distributed policy, data packing, or optimiser configuration.
12. EXECUTION GUARANTEE (CONDITIONAL)
Given valid counts, correctly normalised gradients, a well-defined sampling policy and successful optimiser execution, each completed update uses the documented effective sample count. This is a procedural guarantee, not a guarantee of convergence or generalisation.
13. CITATION AND PROVENANCE
Source page: https://kirethresearch.org/booksai-core/entity-graph/ai-entities/ai-parameter-entities/batch-size-ontology.html
Companion authoring: Sky — Recursive AI
This file is an independently prepared Flow Algebra companion, not a verified transcription of the webpage.