Skip to content

Notebook · Notebook without plots · Python · Python without plots

Model a machine-learning workflow

Training and inference consume resources in different ways. A training run can occupy a large machine for hours; inference repeats smaller operations as users make requests. Describe them as separate usage patterns so their volumes and contributions remain visible.

Start with a rough estimate of both activities within your assessment boundary, then refine the assumptions that drive the result. A small, infrequent training workload need not receive the same modeling effort as the dominant activity. The worked example below uses illustrative GPU workloads on your own infrastructure.

Load the scenario in the interface. Install efootprint to run the Python cells.

Choose the modeling approach

  • For CPU work you operate, use a Job on a Server.
  • For GPU work you operate, use a GPUJob on a GPUServer, as in this example. Server capacity and job compute needs are expressed in GPUs, rather than CPU cores.
  • For requests to a third-party generative-AI API, use EcoLogitsGenAIExternalAPI and its request job. That integration estimates API-request impacts from provider/model data; inspect its assumptions and coverage before interpreting the result.

Choose the approach from the activity and infrastructure you are assessing. An estimate of your API calls is not an assessment of all training performed by their provider. Fine-tuning and serving a model on your own infrastructure belong to the workloads you describe yourself.

Training infrastructure

Treat one training run as a job, linked to the hardware that performs it. The server's compute is the GPU capacity of one instance; the job's compute_needed is the number needed during one run. Its duration turns that resource demand into work over time. Do not put an already time-multiplied GPU-hours value into the GPU-count input.

Obtain per-run inputs from representative training runs: elapsed time, GPUs used, RAM needs, transferred data and net retained data such as checkpoints. Separate what the run reads or transfers from what remains stored afterwards. Record the source of those estimates on the input values.

.from_defaults() fills unspecified hardware inputs with defaults. GPU count alone does not identify a real accelerator: check per-GPU power, manufacturing and the rest of the server against your hardware. Energy measurements can help check the modeled electricity, provided their hardware boundary is comparable; do not add that measured energy a second time on top of modeled electricity.

from efootprint.abstract_modeling_classes.source_objects import SourceValue
from efootprint.builders.timeseries import ExplainableHourlyQuantitiesFromFormInputs
from efootprint.constants.countries import Countries
from efootprint.constants.sources import Sources
from efootprint.constants.units import u
from efootprint.core.hardware.device import Device
from efootprint.core.hardware.gpu_server import GPUServer
from efootprint.core.hardware.network import Network
from efootprint.core.hardware.server_base import ServerTypes
from efootprint.core.hardware.storage import Storage
from efootprint.core.system import System
from efootprint.core.usage.job import GPUJob
from efootprint.core.usage.usage_journey import UsageJourney
from efootprint.core.usage.usage_journey_step import UsageJourneyStep
from efootprint.core.usage.usage_pattern import UsagePattern


training_storage = Storage.from_defaults("Training dataset storage")
training_server = GPUServer.from_defaults(
    "Training GPU server", server_type=ServerTypes.autoscaling(),
    compute=SourceValue(8 * u.gpu), storage=training_storage)
training_job = GPUJob(
    "Annual retraining", server=training_server,
    request_duration=SourceValue(8 * u.hour),
    compute_needed=SourceValue(8 * u.gpu),
    ram_needed=SourceValue(640 * u.GB_ram),
    data_transferred=SourceValue(500 * u.GB),
    data_stored=SourceValue(50 * u.GB_stored))

Inference infrastructure

Use a representative request to estimate inference resources. If you measured a batch, decide whether one modeled occurrence is a batch or a request, then keep its duration, resource needs and demand count consistent. Mixing batch costs with individual-request counts gives the wrong total.

This example uses a separate inference server and storage so that training and serving can be sized independently. Share a server object instead when the workloads really share that hardware. Provisioning mode is another choice: server_type controls fixed, autoscaling or fractional serverless capacity.

inference_storage = Storage.from_defaults("Inference cache storage")
inference_server = GPUServer.from_defaults(
    "Inference GPU server", server_type=ServerTypes.autoscaling(),
    compute=SourceValue(4 * u.gpu), storage=inference_storage)
inference_job = GPUJob(
    "Inference GPU job", server=inference_server,
    request_duration=SourceValue(2 * u.s),
    compute_needed=SourceValue(1 * u.gpu),
    ram_needed=SourceValue(40 * u.GB_ram),
    data_transferred=SourceValue(20 * u.kB),
    data_stored=SourceValue(0 * u.kB_stored))

Define the unit of activity

Put each job in its own step and journey. One occurrence of training_journey then means one training run; one occurrence of inference_journey means one inference request. The usage patterns will repeat those journeys according to their respective demand, without recreating jobs or hardware for every call.

When inference includes an end-user device, also check the step's user_time_spent default. Device-use time is a separate assumption from the server job's request duration.

training_step = UsageJourneyStep.from_defaults("Training run", jobs=[training_job])
training_journey = UsageJourney("Retraining journey", uj_steps=[training_step])
inference_step = UsageJourneyStep.from_defaults("Inference call", jobs=[inference_job])
inference_journey = UsageJourney("Inference journey", uj_steps=[inference_step])

network = Network.wifi_network()
laptop = Device.laptop()
france = Countries.FRANCE()
start_date = "2025-01-01"

Editable annual demand

Give each journey its own demand profile. Training counts runs; inference counts requests. Changing retraining frequency should not also change the number of user requests. The training pattern has no end-user device, while the inference pattern includes a laptop. Check those boundaries and the network assumption against the service you are assessing.

The form-input builder spreads annual training volume uniformly across hours. It describes average demand, rather than scheduled training bursts. That simplification can change provisioned capacity and its footprint. Use custom hourly timeseries when the schedule matters; edit those values in Python and re-export, since the interface cannot manually edit them.

training_pattern = UsagePattern(
    "Annual retraining pattern", [training_journey], [], network, france,
    ExplainableHourlyQuantitiesFromFormInputs({
        "start_date": start_date,
        "modeling_duration_value": 3,
        "modeling_duration_unit": "year",
        "initial_volume": 12,
        "initial_volume_timespan": "year",
        "net_growth_rate_in_percentage": 0,
        "net_growth_rate_timespan": "year",
    }, source=Sources.USER_DATA))
inference_pattern = UsagePattern(
    "Production inference pattern", [inference_journey], [laptop], network, france,
    ExplainableHourlyQuantitiesFromFormInputs({
        "start_date": start_date,
        "modeling_duration_value": 3,
        "modeling_duration_unit": "year",
        "initial_volume": 73000,
        "initial_volume_timespan": "year",
        "net_growth_rate_in_percentage": 25,
        "net_growth_rate_timespan": "year",
    }, source=Sources.USER_DATA))

system = System(
    "Machine learning workflow system", [training_pattern, inference_pattern],
    edge_usage_patterns=[])

Inspect results

Compare training and inference over the same modeled period before deciding where to refine the model. Execution counts alone do not tell us which activity dominates: a training run and an inference request represent different amounts of work.

The loop below asks the attribution layer for each pattern's contribution. It adds manufacturing and use, then sums the hourly quantities over the period. These activity totals include the infrastructure attributed to each pattern, so they can be compared on the same footprint basis.

For per-run or per-request results, divide by the matching activity's occurrence count and state that unit explicitly. See the web tutorial for broader attribution views and the export lesson for file options.

print("Period total:", system.total_footprint.sum().display_quantity)
print("Training starts:", training_pattern.hourly_occurrences.sum().display_quantity)
print("Inference starts:", inference_pattern.hourly_occurrences.sum().display_quantity)
from efootprint.core import attribution
from efootprint.core.lifecycle_phases import LifeCyclePhases

for activity, pattern in (("Training", training_pattern), ("Inference", inference_pattern)):
    footprint = sum(attribution.attributed_footprint(pattern, phase) for phase in LifeCyclePhases)
    print(activity, "footprint:", footprint.sum().display_quantity)
2026-12-01 12:18:18,704 - INFO - Imported BoaviztaCloudServer in 0.03192 seconds.


Period total: 11.7 metric_ton
Training starts: 36.0 occurrence
Inference starts: 278.0 kilooccurrence
Training footprint: 7.58 metric_ton
Inference footprint: 4.16 metric_ton

Pitfalls

  • Treating defaults as hardware measurements. Power, manufacturing, utilization and electricity assumptions can change the conclusion. Keep measured inputs and hypotheses distinguishable through their sources.
  • Mixing units of activity. Per-batch measurements need batch counts; per-request measurements need request counts. Multiply by duration through the job model once, rather than supplying GPU-hours as a GPU count.
  • Omitting work inside the assessment boundary. Significant data preparation, evaluation or CPU preprocessing may need additional jobs and hardware. A GPU job does not describe every part of a training pipeline automatically.
  • Counting the same inference twice. Represent calls through either your own modeled infrastructure or an external API estimate for that work. Combining both for the same calls duplicates their contribution.