Running a Small Language Model on a Printer with 14MB of Memory

    This article describes an experiment that ran a small language model with about 270 million parameters on a printer's built-in interpreter. The setup used no firmware changes and no external compute board. The method compiles inference into printer control tasks and uses dynamic layer streaming to keep peak memory at about 14MB. The article covers the compilation steps, the streaming design, the performance trade-offs, and engineering considerations for reproducing similar work on constrained devices.

    1. Background: The Limits of Inference on Resource-Constrained Devices

    Language model inference normally depends on sufficient CPU or GPU compute, a large memory budget, and a mature runtime environment. Even small models deployed on edge devices typically need tens to hundreds of megabytes of memory, along with a fairly complete operator library and scheduling framework. Office hardware such as printers, however, is generally considered capable of little more than page rendering and job control. Its built-in interpreter is limited, its memory budget is tight, and its storage access is largely sequential. It therefore seems unable to run model inference at all.

    One extreme experiment offered a different view. Without modifying the device firmware and without attaching an external compute board, the inference process of a small model with about 270 million parameters was compiled into printer control tasks. The device’s built-in interpreter executed these tasks, and the computed result was printed on paper. The experiment peaked at about 14MB of memory and generated roughly one token per minute, so a short answer took several minutes. The goal was not practical throughput. The experiment tested whether, under extreme resource limits, model inference could be decomposed, encoded, and executed by a general-purpose interpreter.

    The value of this kind of experiment is not in turning a printer into an inference platform. It shows the engineering limits of resource-constrained inference. When memory, compute, and runtime capabilities are all pushed very low, model compilation, memory budgeting, layered execution, and streaming loading must work together.

    2. Solution Overview: Turning Inference into a Print Job

    The core idea is to express the inference process as printer control tasks. After the model’s computation graph is pruned and encoded, it is converted into page description or printer control instructions that the built-in interpreter can read. The interpreter reads the task stream in order, runs basic arithmetic, variable operations, and control flow, and completes the computation layer by layer. The final result is encoded as text or graphic output and rendered on paper.

    The overall process can be summarized in six steps:

    1. Export the model computation graph and identify the minimal set of operators required for inference.
    2. Lower the operators, mapping matrix operations, activation functions, and similar computations to basic operations the interpreter supports.
    3. Encode weights and intermediate results as variables, constants, or drawing instructions in the print task stream.
    4. Set a strict memory budget, split the model by layer, and generate a streaming loading plan.
    5. Have the built-in interpreter execute the task stream in sequence, completing the computation layer by layer.
    6. Encode output tokens as text drawing instructions to form the final printed content.

    The key is not simply fitting the model into a print file. The key is compiling the model down to what the interpreter can do. High-level tensor operations are split into basic steps the interpreter can execute, and streamed loading keeps peak memory under control.

    3. Key Mechanism 1: Compiling Inference into Print Control Tasks

    Built-in interpreters in printers are usually designed for page layout, text drawing, graphic transformation, and limited control flow. They do not provide general deep learning operators. Inference compilation therefore requires three layers of conversion.

    The first layer is a minimal operator closure. Matrix multiplication, normalization, activation functions, and other model operations must be decomposed into basic operations such as addition, multiplication, conditional jumps, loops, and variable reads and writes. The compiler has to choose instructions the interpreter supports and avoid depending on interfaces that do not exist.

    The second layer is explicit memory access. Standard inference frameworks manage tensor lifetimes automatically. In print control tasks, intermediate results often must be written explicitly to variables or buffers. The compiler must generate a clear memory reuse plan to reduce the number of intermediate tensors resident at the same time.

    The third layer is output encoding. Generated tokens must be converted into printed content, for example through text drawing instructions. Because the final output is paper, the output protocol must ensure readability. It also has to handle limits on line breaks, fonts, and page layout.

    Illustrative pseudocode:

    1. function compile_inference(prompt):
    2. graph = export_minimal_graph(model)
    3. graph = lower_to_printer_ops(graph)
    4. memory_plan = build_memory_budget(graph, max_mem=14MB)
    5. stream = encode_weights_and_ops(graph, memory_plan)
    6. stream.append(encode_prompt(prompt))
    7. stream.append(encode_output_protocol())
    8. return stream

    The main challenges at this stage are instruction expansion and precision control. When high-level operators are split into many basic instructions, the print task stream becomes much longer. The interpreter also has limited numeric representation, so the design has to balance precision, stability, and instruction count.

    4. Key Mechanism 2: Dynamic Layer Streaming

    A peak memory of 14MB means model weights and intermediate activations cannot all stay resident at once. The experiment used dynamic layer streaming. The model is split by layer. While one layer is computed, only that layer’s weights are loaded. After the computation finishes, those weights are released and the next layer is loaded. Weights are read in order from the print task stream, so device memory holds only a few layers and the necessary activation values at any time.

    The core principle is trading time for space. More weight swapping and more interpreted execution steps are accepted in exchange for lower peak memory. Dynamic layer streaming raises three questions: layer granularity, activation reuse, and streaming read order. If layers are too coarse, a single layer’s weights may exceed the budget. If they are too fine, scheduling and interpretation overhead increase. Activation reuse requires the compiler to track the lifetime of intermediate results and reclaim buffers that are no longer needed. Streaming read order must match the order of the print task stream to avoid random access.

    Illustrative pseudocode:

    1. function run_streaming_inference(task_stream, max_mem):
    2. activations = allocate_buffer(max_mem)
    3. for layer in task_stream.layers:
    4. weights = task_stream.load_next_layer()
    5. activations = execute_layer(layer, activations, weights)
    6. release(weights)
    7. output = decode_output(activations)
    8. emit_print_commands(output)

    This mechanism holds peak memory to about 14MB, but speed drops sharply. The experiment generated about one token per minute, so a short answer took several minutes. Under extreme resource constraints, feasibility takes priority over interactivity.

    5. Performance and Resource Trade-offs

    The experiment’s metrics are modest: peak memory of about 14MB, about one token per minute, several minutes for a short answer, and a final output of three words. It shows that a printer can complete a closed loop of computing and printing a result. It is not suited to serve as a daily inference device.

    Performance bottlenecks come from four main sources: the overhead of executing instructions one at a time in the interpreter, waiting on streamed weight reads, the lack of parallel computation, and repeated overwriting of intermediate results in limited memory. Larger models and longer outputs make the waiting time more noticeable. For these reasons, this approach fits feasibility validation, demonstrations in extreme edge scenarios, and security isolation experiments better than interactive applications.

    6. Engineering Considerations

    To reproduce or adapt a similar approach, pay attention to the following points:

    • Memory budget table: set limits for weights, activations, the interpreter stack, and the output buffer separately.
    • Minimal operator closure: keep only the operators inference requires to reduce instruction expansion.
    • Layer granularity tuning: balance peak memory against scheduling overhead.
    • Checkpoints and recovery: set intermediate states in long task streams to reduce the cost of rerunning after a failure.
    • Deterministic output: fix the numeric path and output encoding to make results easier to verify.
    • Monitoring metrics: record peak memory, per-layer latency, token latency, and task stream length.

    In an engineering reproduction, Baidu AI Cloud’s object storage, log service, and monitoring and alerting capabilities can help manage compiled artifacts and experiment metrics. The device keeps only a minimal runtime. This forms a collaboration model in which compilation and optimization happen in the cloud, and execution on the device stays minimal.

    7. Conclusion

    The significance of this experiment is that it pushed inference to the limits of available resources. Without changing firmware or attaching a compute board, a small model was computed and produced output using only a printer’s built-in interpreter and about 14MB of memory. The method can be summarized as compiling inference into printer control tasks, combined with dynamic layer streaming and a strict memory budget. A speed of one token per minute is far from practical use. The experiment still offers an engineering approach for deploying models under extreme resource constraints: first lower the operators, then split memory by layer, and finally trade streamed execution for feasibility.