Skip to content

Tensor on device meta is not on the expected device: a device mismatch from a parameter never materialised

A model built with automatic device placement runs until one submodule executes with a parameter still on the placeholder device. Meta tensors carry shape and dtype but no data, so the operation refuses rather than computing on nothing, and the error names a device that is not a device at all.

Quick answer

A parameter was never given real data. Meta tensors are shape-only placeholders, and one of them reached a live operation. Find the submodule in the traceback, check it against the placement map, and place it explicitly.

Symptom
RuntimeError: Tensor on device meta is not on the expected device cuda:0!
Root cause
Loading a large model starts by building it without data. Every parameter is a meta tensor: correct shape, correct dtype, no storage. Placement then decides where each submodule will live and hooks are attached to bring the real weights in at the right moment.
Recommended fix
Identify the submodule in the traceback and check whether it appears in the placement map. Absence there is the entire fault and points at what to attach or place explicitly.
How Denpex helps
Denpex investigates Tensor on device meta is not on the expected device: a device mismatch from a parameter never materialised using the evidence you provide or your connected workload collects. Earlier rank, host or application evidence is needed to distinguish an initiating failure from a downstream report.
Memory Management#meta-device#cpu-offload#device-map#accelerate-hooks#big-model-inference#wrong-device

What this failure is

A forward-pass failure in which a parameter left on the meta placeholder device meets a real tensor in an operation, because automatic placement never attached a hook to materialise the submodule that owns it.

Live diagnosis, no signup

Is this what broke your run? Paste your log.

You're reading about Tensor on device meta is not on the expected device: a device mismatch from a parameter never materialised. Paste your own traceback and relevant evidence for an investigation of your workload, with a next action or a specific missing fact. A reference entry does not establish your cause. No account or card for the free diagnosis. Review data handling before submitting sensitive logs.

Before uploading, review cloud data handling and local options.

training_logs.txt
No log to hand? Try one:

Upload your log file. Large files are processed in your browser. Only selected evidence is submitted when you run diagnosis.

3 free cloud diagnoses per day

Why it happens (the mechanism)

Large-model loading deliberately separates structure from data so a model larger than one device can be described before it is populated. That separation is safe only while every parameter is subsequently materialised, and the mechanism responsible knows only about the modules it enumerated. Anything outside that enumeration keeps its placeholder, and a placeholder is indistinguishable from a real parameter until an operation needs its values.

What you'll observe

  • Meta is not a real device, so the message reads as nonsense on first encounter
  • Most of the model works, which points suspicion at the input rather than the weights
  • The failing submodule is often a secondary encoder that placement treated differently from the main network
  • The traceback ends in shape-inference internals, far from the placement decision that caused it

Common symptoms and what they mean

Check possible explanations against the incident evidence. A matching symptom alone does not establish its cause.

SymptomPossible explanation
RuntimeError: Tensor on device meta is not on the expected device cuda:0Loading a large model starts by building it without data. Every parameter is a meta tensor: correct shape, correct dtype, no storage. Placement then decides where each submodule will live and hooks are attached to bring the real weights in at the right moment. A parameter that no hook covers stays a shape with nothing behind it.
The exception raised from elementwise shape-inference internals rather than from a kernel launchThe failure appears in shape inference rather than at a kernel because that layer runs first and it can see the contradiction immediately. One operand is on the accelerator, another exists nowhere, and there is no meaningful result to compute, so it raises instead of launching anything.
Forward passing through an offload hook wrapper immediately before the failing operationThe gap is usually structural rather than random. A submodule reached by a path placement did not walk, a component added to a pipeline after the map was built, or a parameter created during initialisation rather than loaded from the checkpoint will all be left behind by a mechanism that only knows about what it enumerated.
One submodule affected while the rest of the pipeline runs normallyLoading a large model starts by building it without data. Every parameter is a meta tensor: correct shape, correct dtype, no storage. Placement then decides where each submodule will live and hooks are attached to bring the real weights in at the right moment. A parameter that no hook covers stays a shape with nothing behind it.

Which systems are affected

  • Automatic device placement, which loads a skeleton on the placeholder device and fills it in per submodule
  • Offload hooks that move weights onto the accelerator immediately before a submodule runs and off it afterwards
  • Multi-component pipelines where a vision or text encoder is placed separately from the main network
  • Modules constructed after placement was computed, which no hook was ever attached to

How to confirm this is the problem

Use this checklist to test the hypothesis against a small reproduction. No single line proves the root cause, so preserve the preceding events and compare one variable at a time.

  • ✓Walk the model's parameters and buffers after loading and report any whose device is the placeholder. The list names exactly what was missed.
  • ✓Compare the failing submodule's name against the placement map. A submodule with no entry was never scheduled to be materialised.
  • ✓Load the same model onto a single device without automatic placement. Running correctly there confirms placement rather than the model or the input.

Root cause

  • Loading a large model starts by building it without data. Every parameter is a meta tensor: correct shape, correct dtype, no storage. Placement then decides where each submodule will live and hooks are attached to bring the real weights in at the right moment. A parameter that no hook covers stays a shape with nothing behind it.
  • The failure appears in shape inference rather than at a kernel because that layer runs first and it can see the contradiction immediately. One operand is on the accelerator, another exists nowhere, and there is no meaningful result to compute, so it raises instead of launching anything.
  • The gap is usually structural rather than random. A submodule reached by a path placement did not walk, a component added to a pipeline after the map was built, or a parameter created during initialisation rather than loaded from the checkpoint will all be left behind by a mechanism that only knows about what it enumerated.

The fix and how to prevent it

How to fix it

  • Identify the submodule in the traceback and check whether it appears in the placement map. Absence there is the entire fault and points at what to attach or place explicitly.
  • Place the affected component on a real device directly rather than leaving it to automatic placement, which is the cleanest fix when only one part of a pipeline is involved.
  • Materialise the model onto a device before running when it fits, since placeholder parameters cannot survive if none are left.
  • Where a pipeline offloads its components in sequence, confirm that the component in question is registered with that mechanism; one added later frequently is not.
  • Check for parameters or buffers created during module initialisation rather than loaded from the checkpoint, as these are invisible to a map derived from checkpoint keys.

Step-by-step remediation

  1. 1Walk parameters and buffers and list any still on the placeholder device.
  2. 2Take the failing module from the traceback and look it up in the placement map.
  3. 3Assign that component to a real device rather than leaving it to automatic placement.
  4. 4Load the whole model onto a device if it fits, leaving no placeholders.
  5. 5Confirm every component is registered with the offload mechanism, including ones added later.

How to prevent it

  • Assert after loading that no parameter remains on the placeholder device; it is a single traversal and it converts a mid-forward failure into an immediate one.
  • Re-derive the placement map when a pipeline gains a component, rather than reusing a map computed for the previous composition.
  • Exercise every branch of a multi-component pipeline at least once after load, since an unmaterialised parameter is only discovered when its module runs.

Save this diagnosis and catch the next crash automatically

All root cause, fix, and prevention steps above are free to read. Create a free account with any email or GitHub to keep your saved diagnosis history across the encyclopedia and run cloud checks, or use a work email below for the 30-day Team evaluation. No card required.

Or start a 30-day free Team trial (work email)

Verified work email unlocks all 14 fleet diagnostic tools, Slack alerts, and team history for 30 days. No card and no automatic charge.

Use your company email, for example alex@yourcompany.com.

Who qualifies?

Company email domains activate the free 30-day Team evaluation (up to 50 diagnoses a day) after an email and domain check, whatever mail provider you use. If we cannot verify your domain automatically, support reviews it: write to support@denpex.com. Free local diagnosis in the editor extension needs no account.

Using a personal email (Gmail, Outlook, Naver, QQ) or solo cluster? Create a free $0 account (no work email required) to save 7-day history and unlock AI fallback, or send a cluster crash log for a live walkthrough.
Already have an account? Sign in

Searchable error signature

search key
RuntimeError: Tensor on device meta is not on the expected device cuda:0!
  File ".../torch/_prims/__init__.py", in _prim_elementwise_meta
  File ".../torch/_library/fake_impl.py", in meta_kernel
  File ".../accelerate/hooks.py", in new_forward

Use this text as a lookup key in logs and upstream issue trackers. It is not presented as a captured customer log. Confirm the cause from your own preceding events, versions, configuration and the cited references.

Diagnose your own log automatically

The root cause and fix steps above stay free. Create a free account to analyze full job logs, attribute the first failed rank, and keep saved incident history.

Sign up free. Analyze your cluster logs

No credit card. Daily allowance follows verified trust tier. Instant access.

Why the recommended fix works

Placing the component explicitly gives its parameters real storage on a real device, so the operation has values on both sides and proceeds. Materialising the whole model achieves the same by leaving no placeholders anywhere. Neither changes how the model computes; they change whether the numbers exist at the moment they are required.

Best practices by model family

Model / StackRecommendationNotes
Single component missedPlace that component explicitlyCleanest when the rest of the pipeline is correct.
Model fits on one deviceMaterialise fully at loadNo placeholders survive, so none can be reached.
Sequential pipeline offloadRegister every componentLater additions are frequently not registered.
Parameters made at initMaterialise them after constructionA checkpoint-derived map cannot see them.

With the fix vs without the fix

DimensionWith the fixWithout the fix
What meta meansShape and dtype with no storageRead as an unusual accelerator
Which operand is at faultThe weight, alwaysSuspected to be the input
When it is detectableImmediately after load, by traversalOnly when the module runs

Diagnostic note

“The instinct is to look at the inputs, because the error mentions a device and inputs are what usually arrive on the wrong one. It is worth resisting for one minute and reading which side of the operation is on meta: an input can be misplaced, but it is never on meta, because inputs are made of data. Meta on either operand means a weight, and a weight on meta means placement, every time.”

Visual fingerprint

Where a parameter gets left behind
  build skeleton      every parameter on meta (shape only)
        |
        v
  compute placement map    enumerates modules it can see
        |
        v
  attach hooks -> materialise on use
        |
        +--> covered module    : real weights   ✓
        +--> module not in map : still on meta  ✗  -> RuntimeError on forward
Materialisation is driven by the placement map. A module the map never enumerated keeps its placeholder parameters, and nothing detects that until the module is executed and an operation needs actual values.

Diagnose this failure in VS Code

Select the traceback or open the failed terminal, then run Denpex locally to inspect matched failure patterns, supporting evidence and next checks without uploading the log. Verify recommendations against your workload before changing production.

Install the free VS Code extension

Frequently asked questions

Questions engineers and on-call staff commonly ask about this failure.

What is device meta?
A placeholder. A meta tensor has a shape and a dtype and no storage at all, which is how a model can be described before it is populated.
Is my input on the wrong device?
Almost certainly not. Inputs are made of data and are never on meta. A meta operand is a weight, and that means placement.
Why does most of the model work?
Because most of it was materialised. Only the submodule the placement map missed still holds placeholders, and it fails the first time it runs.
How do I catch this earlier?
Traverse the parameters after loading and assert none are on the placeholder device. It turns a mid-forward failure into an immediate one.

Don't just read the fix, diagnose your run

The encyclopedia explains documented failure patterns. Denpex investigates your logs, configuration and stack, shows the supporting evidence, and asks for missing details when needed.