WOLFRAM

NetExternalObject
NetExternalObject

Updatedshow changeshide changes[Experimental]

represents a net model in an external framework format.

Details

  • NetExternalObject is typically used to run inference using neural network models not defined in the Wolfram Language.
  • Supported file formats are:
  • "ONNX"ONNX models
    "MXNet"MXNet models
    "GGUF"GGUF models
  • For a model with a single input port, NetExternalObject[][data] gives the result of applying the model to data.
  • For a model with multiple input ports, NetExternalObject[][<|port1data1,|>] provides datai to porti.
  • When data is given as NumericArray, the output will be a NumericArray. »
  • Information[NetExternalObject[]] generates an information panel about the model. »
  • Information of a NetExternalObject may include the following properties:
  • "Backend"the evaluation back end used by the model
    "ContextWindowSize"current maximum size of the model context windows
    "InputPortNames"list of names of input ports
    "InputPorts"association of input port shapes
    "OutputPortNames"list of names of output ports
    "OutputPorts"association of output port shapes
    "Properties"available properties
    "RawData"unprocessed native contents of the model
    "TrainingContextWindowSize"original size of the model context windows
  • NetExternalObject[][data,opts] specifies that options should be used in applying the net to data. Possible options include:
  • Method Automaticspecify details of the model evaluation
    TargetDevice "CPU"the device on which to perform evaluation
  • Possible settings for TargetDevice change depending on the system and the hardware and include:
  • "CPU"use the CPU
    "GPU"use available dedicated hardware
    "CoreML"Apple CoreML framework
    "CUDA"Nvidia CUDA API
    "DirectML"Microsoft Direct Machine Learning API
  • For a NetExternalObject with LLaMA.cpp backend ("GGUF" format) that generates text, option Method can be set to a list of rules having any of the following keys:
  • "MaxTokens"Automaticmaximum number of generated tokens
    RandomSeedingAutomaticwhat seeding of pseudorandom generators should be done internally
    "PrependPrompt"Falsewhether to prepend the input to ext to the output text
    "ResetState"Truewhether to reset the language model's state before processing the input
    "StopTokens"{}a list of strings that should stop the generation if produced

Examples

open allclose all

Basic Examples  (2)Summary of the most common use cases

Import an ONNX model as an external network:

Out[1]=1

Evaluate the model on some input data:

Out[2]=2

Import a quantized image classifier:

Out[1]=1

Define a minimal pipeline to pre- and post-process the data:

Run the external model:

Out[3]=3

Scope  (5)Survey of the scope of standard use cases

Formats  (3)

Import an ONNX model as a NetExternalObject:

Out[1]=1

Import a net in GGUF format (model credit: Olusegun Odewole, https://huggingface.co/segestic/Tinystories-gpt-0.1-3m ):

Out[1]=1

Import an MXNet model as a NetExternalObject:

Out[1]=1

Properties  (2)

Extract a property of the external net using Information:

Out[1]=1
Out[2]=2

Get a list of properties:

Out[3]=3

Get a list of all the supported properties:

Out[1]=1
Out[2]=2

Options  (4)Common values & functionality for each option

Method  (2)

Import a text-generating model:

Out[1]=1

Run the model until a termination token is reached:

Out[9]=9

Prepend the prompt to the generated text:

Out[10]=10

Specify a maximum amount of tokens to generate:

Out[28]=28

Text generation is a random process:

Out[2]=2

Fix the seed of the pseudorandom generator to get reproducible results:

Out[3]=3

TargetDevice  (2)

Import an ONNX file and run it on the CPU:

Out[1]=1
Out[2]=2

Run the model using CoreML:

Out[3]=3

Some models will run faster when evaluated on specialized hardware:

Out[1]=1

Timing on CPU:

Out[2]=2

Timing on CoreML:

Out[3]=3

Applications  (3)Sample problems that can be solved with this function

Run a real-time face detector:

Out[2]=2

Define a transformation from an image to a list of arrays:

Out[3]=3

Run the detector on the encoded image:

Out[4]=4

Extract the bounding box and probability information from the result:

Visualize the detections, filtering the ones with low probability or large overlap:

Out[7]=7

This network can analyze more that 40 images per second on a consumer laptop:

Out[9]=9

Import a text-generating model:

Out[1]=1

Run the model until a termination token is reached:

Out[2]=2

Import a "GGUF" file as an embedding model:

Out[1]=1

Generate an embedding vector for each token in a string:

Properties & Relations  (2)Properties of the function, and connections to other functions

Input given as a NumericArray will cause the output to also be a NumericArray:

Out[1]=1
Out[2]=2

External net models typically have a hard-coded batch dimension:

Out[1]=1
Out[2]=2

Ordinary networks do not have an explicit batch dimension:

Out[3]=3

They work both on single examples and batches of any size:

Out[4]=4
Out[5]=5
Out[6]=6

Possible Issues  (2)Common pitfalls and unexpected behavior

External models cannot be modified:

Out[1]=1
Out[2]=2

External models cannot be retrained:

Out[1]=1
Out[2]=2
Wolfram Research (2022), NetExternalObject, Wolfram Language function, https://reference.wolfram.com/language/ref/NetExternalObject.html (updated 2025).
Wolfram Research (2022), NetExternalObject, Wolfram Language function, https://reference.wolfram.com/language/ref/NetExternalObject.html (updated 2025).

Text

Wolfram Research (2022), NetExternalObject, Wolfram Language function, https://reference.wolfram.com/language/ref/NetExternalObject.html (updated 2025).

Wolfram Research (2022), NetExternalObject, Wolfram Language function, https://reference.wolfram.com/language/ref/NetExternalObject.html (updated 2025).

CMS

Wolfram Language. 2022. "NetExternalObject." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2025. https://reference.wolfram.com/language/ref/NetExternalObject.html.

Wolfram Language. 2022. "NetExternalObject." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2025. https://reference.wolfram.com/language/ref/NetExternalObject.html.

APA

Wolfram Language. (2022). NetExternalObject. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/NetExternalObject.html

Wolfram Language. (2022). NetExternalObject. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/NetExternalObject.html

BibTeX

@misc{reference.wolfram_2025_netexternalobject, author="Wolfram Research", title="{NetExternalObject}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/NetExternalObject.html}", note=[Accessed: 07-June-2025 ]}

@misc{reference.wolfram_2025_netexternalobject, author="Wolfram Research", title="{NetExternalObject}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/NetExternalObject.html}", note=[Accessed: 07-June-2025 ]}

BibLaTeX

@online{reference.wolfram_2025_netexternalobject, organization={Wolfram Research}, title={NetExternalObject}, year={2025}, url={https://reference.wolfram.com/language/ref/NetExternalObject.html}, note=[Accessed: 07-June-2025 ]}

@online{reference.wolfram_2025_netexternalobject, organization={Wolfram Research}, title={NetExternalObject}, year={2025}, url={https://reference.wolfram.com/language/ref/NetExternalObject.html}, note=[Accessed: 07-June-2025 ]}