Skip to content

[Bug] AttributeError: 'Embedding' object has no attribute 'in_features' #4166

@ferreroal

Description

@ferreroal

After doing some continued pretraining to Qwen3.5-35B-A3B-Base with LoRA i wanted to merge the adapters into the main model with model.save_pretrained_merged() but i got an error about Embedding.

I trained the following target_modules: "q_proj, k_proj, v_proj, o_proj, down_proj, up_proj, gate_proj, embed_tokens, lm_head" and saved them all after training, then loaded the trained model and merged with this code

  model, tokenizer = FastLanguageModel.from_pretrained(args.model_path)
  model.save_pretrained_merged(tokenizer=tokenizer, save_method="merged_16bit", save_directory=args.output_dir)

Besides the error i also got a warning about a LoRA count mismatch and an unsupported layer in Qwen3_5MoeExperts

Full stack trace

Details
/opt/conda/lib/python3.11/site-packages/peft/tuners/tuners_utils.py:212: UserWarning: Unsupported layer type '<class 'transformers.models.qwen3_5_moe.modeling_qwen3_5_moe.Qwen3_5MoeExperts'>' encountered, proceed at your own risk.
  warnings.warn(f"Unsupported layer type '{type(module)}' encountered, proceed at your own risk.", UserWarning)
[Unsloth merge debug] LoRA count mismatch: modules=202, lora_A=241, lora_B=241, scaling=242
[Unsloth merge debug] Total LoRA keys: 242
  key=model.language_model.embed_tokens param=None A=None B=None
  key=model.language_model.layers.0.mlp.experts param=None A=(4096, 2048) B=(512, 4096)
  key=model.language_model.layers.0.mlp.experts.base_layer param=None A=(4096, 1024) B=(2048, 4096)
  key=model.language_model.layers.0.mlp.shared_expert.gate_proj param=None A=(16, 2048) B=(512, 16)
  key=model.language_model.layers.0.mlp.shared_expert.up_proj param=None A=(16, 2048) B=(512, 16)
  key=model.language_model.layers.0.mlp.shared_expert.down_proj param=None A=(16, 512) B=(2048, 16)
  key=model.language_model.layers.1.mlp.experts param=None A=(4096, 2048) B=(512, 4096)
  key=model.language_model.layers.1.mlp.experts.base_layer param=None A=(4096, 1024) B=(2048, 4096)
  key=model.language_model.layers.1.mlp.shared_expert.gate_proj param=None A=(16, 2048) B=(512, 16)
  key=model.language_model.layers.1.mlp.shared_expert.up_proj param=None A=(16, 2048) B=(512, 16)
Traceback (most recent call last):
  File "/mnt/azureml/cr/j/825a13e46b4d4245bec7d53fbd0d4d8d/exe/wd/unsloth_to_vllm.py", line 49, in <module>
    main()
  File "/mnt/azureml/cr/j/825a13e46b4d4245bec7d53fbd0d4d8d/exe/wd/unsloth_to_vllm.py", line 43, in main
    model.save_pretrained_merged(
  File "/opt/conda/lib/python3.11/site-packages/unsloth/save.py", line 2714, in unsloth_generic_save_pretrained_merged
    unsloth_generic_save(**arguments)
  File "/opt/conda/lib/python3.11/site-packages/torch/utils/_contextlib.py", line 120, in decorate_context
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/unsloth/save.py", line 2662, in unsloth_generic_save
    merge_and_overwrite_lora(
  File "/opt/conda/lib/python3.11/site-packages/torch/utils/_contextlib.py", line 120, in decorate_context
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/unsloth_zoo/saving_utils.py", line 1771, in merge_and_overwrite_lora
    ) = prepare_saving(
        ^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/unsloth_zoo/saving_utils.py", line 1485, in prepare_saving
    save_size = sum(get_torch_storage_size_new(x, element_size) for x in state_dict.values())
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/unsloth_zoo/saving_utils.py", line 1485, in <genexpr>
    save_size = sum(get_torch_storage_size_new(x, element_size) for x in state_dict.values())
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/unsloth_zoo/saving_utils.py", line 1418, in get_torch_storage_size_new
    shape = (x.module.in_features, x.module.out_features)
             ^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1964, in __getattr__
    raise AttributeError(
AttributeError: 'Embedding' object has no attribute 'in_features'

Pip freeze

Details
absl-py==2.4.0
accelerate==1.12.0
addict==2.4.0
aiofiles==24.1.0
aiohappyeyeballs==2.6.1
aiohttp==3.13.3
aiosignal==1.4.0
annotated-doc==0.0.4
annotated-types==0.7.0
anthropic==0.71.0
antlr4-python3-runtime==4.9.3
anyio==4.12.1
apache-tvm-ffi==0.1.8.post2
archspec @ file:///home/conda/feedstock_root/build_artifacts/archspec_1737352602016/work
argbind==0.3.9
argon2-cffi==25.1.0
argon2-cffi-bindings==25.1.0
arrow==1.4.0
astor==0.8.1
asttokens==3.0.1
async-lru==2.1.0
attrs==25.4.0
audioread==3.1.0
Authlib==1.6.7
azure-core==1.38.2
azure-identity==1.16.0
azure-storage-blob==12.20.0
babel==2.18.0
beautifulsoup4 @ file:///home/conda/feedstock_root/build_artifacts/beautifulsoup4_1759146011391/work
bitsandbytes==0.49.1
blake3==1.0.8
bleach==6.3.0
boltons @ file:///home/conda/feedstock_root/build_artifacts/boltons_1749686179973/work
Brotli @ file:///home/conda/feedstock_root/build_artifacts/brotli-split_1756599151967/work
build==1.3.0
cachetools==7.0.0
cattrs==25.3.0
causal_conv1d @ git+https://github.com/Dao-AILab/causal-conv1d.git@69e6dadc28b169a4c49cb86b586f64ee90242c70
cbor2==5.8.0
certifi==2026.1.4
cffi @ file:///home/conda/feedstock_root/build_artifacts/cffi_1758716116344/work
chardet @ file:///home/conda/feedstock_root/build_artifacts/chardet_1741797914774/work
charset-normalizer==3.4.4
click @ file:///home/conda/feedstock_root/build_artifacts/click_1758270398201/work
cloudpickle==3.1.2
cmake==4.1.0
colorama @ file:///home/conda/feedstock_root/build_artifacts/colorama_1733218098505/work
comm==0.2.3
compressed-tensors==0.12.2
conda @ file:///home/conda/feedstock_root/build_artifacts/conda_1754405241914/work/conda-src
conda-build @ file:///home/conda/feedstock_root/build_artifacts/conda-build_1759317057030/work
conda-libmamba-solver @ file:///home/conda/feedstock_root/build_artifacts/conda-libmamba-solver_1745834476052/work/src
conda-package-handling @ file:///home/conda/feedstock_root/build_artifacts/conda-package-handling_1736345463896/work
conda_index @ file:///home/conda/feedstock_root/build_artifacts/conda-index_1748375757308/work
conda_package_streaming @ file:///home/conda/feedstock_root/build_artifacts/conda-package-streaming_1751548120229/work
contourpy==1.3.3
coremltools==9.0
cryptography==46.0.4
cuda-bindings==12.8.0
cuda-pathfinder==1.3.3
cuda-python==12.8.0
cupy-cuda12x==13.6.0
cut-cross-entropy==25.1.1
cycler==0.12.1
datasets==4.3.0
debugpy==1.8.20
decorator==5.2.1
defusedxml==0.7.1
depyf==0.20.0
descript-audio-codec==1.0.0
descript-audiotools==0.7.2
diffusers==0.36.0
dill==0.4.0
diskcache==5.6.3
distro @ file:///home/conda/feedstock_root/build_artifacts/distro_1734729835256/work
dnspython==2.8.0
docstring_parser==0.17.0
download_from_azure_storage==0.2.8
easydict==1.13
einops==0.8.1
einx==0.3.0
email-validator==2.3.0
evalidate @ file:///home/conda/feedstock_root/build_artifacts/bld/rattler-build_evalidate_1746793833/work
evaluate==0.4.6
exceptiongroup @ file:///home/conda/feedstock_root/build_artifacts/exceptiongroup_1746947292760/work
execnet==2.1.2
executing==2.2.1
executorch==1.0.1
expecttest==0.3.0
fastapi==0.128.7
fastapi-cli==0.0.20
fastapi-cloud-cli==0.11.0
fastar==0.8.0
fastjsonschema==2.21.2
fastrlock==0.8.3
ffmpy==1.0.0
filelock==3.20.3
fire==0.7.1
flashinfer-python==0.5.2
flatbuffers==25.12.19
flatten-dict==0.4.2
fonttools==4.61.1
fqdn==1.5.1
frozendict @ file:///home/conda/feedstock_root/build_artifacts/frozendict_1756047915708/work
frozenlist==1.8.0
fsspec==2025.3.0
ftfy==6.3.1
gguf==0.17.1
gitdb==4.0.12
GitPython==3.1.46
gradio==6.5.1
gradio_client==2.0.3
groovy==0.1.2
grpcio==1.78.0
h11==0.16.0
h2 @ file:///home/conda/feedstock_root/build_artifacts/h2_1738578511449/work
hf-xet==1.2.0
hf_transfer==0.1.9
hpack @ file:///home/conda/feedstock_root/build_artifacts/hpack_1737618293087/work
httpcore==1.0.9
httptools==0.7.1
httpx==0.28.1
huggingface_hub==1.4.1
hydra-core==1.3.2
hyperframe @ file:///home/conda/feedstock_root/build_artifacts/hyperframe_1737618333194/work
hypothesis==6.141.0
idna==3.11
importlib_metadata==8.7.1
importlib_resources==6.5.2
iniconfig==2.3.0
interegular==0.3.3
ipykernel==6.30.1
ipython==9.10.0
ipython_pygments_lexers==1.1.1
ipywidgets==8.1.8
isodate==0.7.2
isoduration==20.11.0
itsdangerous==2.2.0
jedi==0.19.2
Jinja2 @ file:///home/conda/feedstock_root/build_artifacts/jinja2_1741263328855/work
jiter==0.13.0
jiwer==4.0.0
jmespath==1.1.0
joblib==1.5.3
json5==0.13.0
jsonpatch @ file:///home/conda/feedstock_root/build_artifacts/jsonpatch_1733814567314/work
jsonpointer @ file:///home/conda/feedstock_root/build_artifacts/jsonpointer_1756754131677/work
jsonschema @ file:///home/conda/feedstock_root/build_artifacts/bld/rattler-build_jsonschema_1755595646/work
jsonschema-specifications @ file:///tmp/tmptzik3dqa/src
julius==0.2.7
jupyter-events==0.12.0
jupyter-lsp==2.3.0
jupyter_client==8.8.0
jupyter_core==5.9.1
jupyter_server==2.17.0
jupyter_server_terminals==0.5.4
jupyterlab==4.5.3
jupyterlab_pygments==0.3.0
jupyterlab_server==2.28.0
jupyterlab_widgets==3.0.16
kernels==0.12.1
kgb==7.3
kiwisolver==1.4.9
langid==1.1.6
lark==1.2.2
latex2sympy2_extended==1.11.0
lazy_loader==0.4
libarchive-c @ file:///home/conda/feedstock_root/build_artifacts/bld/rattler-build_python-libarchive-c_1754663558/work
libmambapy @ file:///home/conda/feedstock_root/build_artifacts/mamba-split_1746515836725/work/libmambapy
librosa==0.11.0
lief @ file:///home/conda/feedstock_root/build_artifacts/lief_1750151383011/work/api/python
lintrunner==0.12.7
llguidance==1.3.0
llvmlite==0.44.0
lm-format-enforcer==0.11.3
loguru==0.7.2
lxml==6.0.2
mamba_ssm @ git+https://github.com/state-spaces/mamba.git@e0761ece1db07e0949dd88b4f4cd440420a19fd9
Markdown==3.10.2
markdown-it-py==4.0.0
markdown2==2.5.4
MarkupSafe @ file:///home/conda/feedstock_root/build_artifacts/markupsafe_1759055168201/work
math-verify==0.3.3
matplotlib==3.10.8
matplotlib-inline==0.2.1
mdurl==0.1.2
mecab==0.996.13
menuinst @ file:///home/conda/feedstock_root/build_artifacts/menuinst_1760126894329/work
mistral_common==1.9.0
mistune==3.2.0
ml_collections==1.1.0
model-hosting-container-standards==0.1.13
more-itertools==10.8.0
mpmath==1.3.0
msal==1.35.0
msal-extensions==1.3.1
msgpack @ file:///home/conda/feedstock_root/build_artifacts/msgpack-python_1759930458348/work
msgspec==0.20.0
multidict==6.7.1
multiprocess==0.70.16
narwhals==2.16.0
nbclient==0.10.4
nbconvert==7.17.0
nbformat==5.10.4
nest-asyncio==1.6.0
networkx==3.5
ninja==1.13.0
notebook==7.5.3
notebook_shim==0.2.4
numba==0.61.2
numpy==2.4.1
nvidia-cublas-cu12==12.8.4.1
nvidia-cuda-cupti-cu12==12.8.90
nvidia-cuda-nvrtc-cu12==12.8.93
nvidia-cuda-runtime-cu12==12.8.90
nvidia-cudnn-cu12==9.10.2.21
nvidia-cudnn-frontend==1.18.0
nvidia-cufft-cu12==11.3.3.83
nvidia-cufile-cu12==1.13.1.3
nvidia-curand-cu12==10.3.9.90
nvidia-cusolver-cu12==11.7.3.90
nvidia-cusparse-cu12==12.5.8.93
nvidia-cusparselt-cu12==0.7.1
nvidia-cutlass-dsl==4.3.5
nvidia-ml-py==13.590.48
nvidia-nccl-cu12==2.27.5
nvidia-nvjitlink-cu12==12.8.93
nvidia-nvshmem-cu12==3.3.20
nvidia-nvtx-cu12==12.8.90
omegaconf==2.3.0
open_spiel==1.6.11
openai==2.18.0
openai-harmony==0.0.8
openai-whisper==20250625
opencv-python-headless==4.13.0.92
openenv-core @ git+https://github.com/meta-pytorch/OpenEnv.git@c35ceb0a605dae2c56f262d2147f42e2e68badb3
optree==0.17.0
orjson==3.11.7
outlines_core==0.2.11
overrides==7.7.0
packaging==26.0
pandas==3.0.0
pandocfilters==1.5.1
parameterized==0.9.0
parso==0.8.6
partial-json-parser==0.2.1.1.post7
pdfminer.six==20260107
peft==0.18.1
pexpect==4.9.0
pickleshare @ file:///home/conda/feedstock_root/build_artifacts/pickleshare_1733327343728/work
pillow==11.3.0
pkginfo @ file:///home/conda/feedstock_root/build_artifacts/pkginfo_1739984581450/work
platformdirs==4.5.1
plotly==6.5.2
pluggy @ file:///home/conda/feedstock_root/build_artifacts/pluggy_1747339660894/work
pooch==1.9.0
prometheus-fastapi-instrumentator==7.1.0
prometheus_client==0.24.1
prompt_toolkit==3.0.52
propcache==0.4.1
protobuf==6.33.5
psutil==5.9.8
ptyprocess==0.7.0
pure_eval==0.2.3
py-cpuinfo==9.0.0
pyaml==26.2.1
pyarrow==23.0.0
pybase64==1.4.3
pybind11==3.0.1
pycosat @ file:///home/conda/feedstock_root/build_artifacts/pycosat_1757744658111/work
pycountry==24.6.1
pycparser @ file:///home/conda/feedstock_root/build_artifacts/bld/rattler-build_pycparser_1733195786/work
pydantic==2.12.5
pydantic-extra-types==2.11.0
pydantic-settings==2.12.0
pydantic_core==2.41.5
pydub==0.25.1
Pygments==2.19.2
PyJWT==2.11.0
pyloudnorm==0.2.0
pyparsing==3.3.2
pyproject_hooks==1.2.0
PySocks @ file:///home/conda/feedstock_root/build_artifacts/pysocks_1733217236728/work
pystoi==0.4.1
pytest==8.4.2
pytest-json-report==1.5.0
pytest-metadata==3.1.1
pytest-rerunfailures==15.1
pytest-xdist==3.8.0
python-codicefiscale==0.11.3
python-dateutil==2.9.0.post0
python-docx==1.2.0
python-dotenv==1.2.1
python-etcd==0.4.5
python-fsutil==0.16.0
python-json-logger==4.0.0
python-multipart==0.0.22
python-pptx==1.0.2
python-slugify==8.0.4
pytorch_tokenizers==1.1.0
pytube==15.0.0
pytz @ file:///home/conda/feedstock_root/build_artifacts/pytz_1742920838005/work
PyYAML==6.0.3
pyzmq==27.1.0
randomname==0.2.1
RapidFuzz==3.14.3
ray==2.53.0
referencing @ file:///home/conda/feedstock_root/build_artifacts/bld/rattler-build_referencing_1760379115/work
regex==2026.1.15
requests==2.32.5
rfc3339-validator==0.1.4
rfc3986-validator==0.1.1
rfc3987-syntax==1.1.0
rich==14.3.2
rich-toolkit==0.19.0
rignore==0.7.6
rpds-py @ file:///home/conda/feedstock_root/build_artifacts/bld/rattler-build_rpds-py_1756737832/work
ruamel.yaml @ file:///home/conda/feedstock_root/build_artifacts/ruamel.yaml_1756839007949/work
ruamel.yaml.clib @ file:///home/conda/feedstock_root/build_artifacts/ruamel.yaml.clib_1756828667033/work
safehttpx==0.1.7
safetensors==0.7.0
scikit-learn==1.7.1
scipy==1.17.0
semantic-version==2.10.0
Send2Trash==2.1.0
sentence-transformers==5.2.0
sentencepiece==0.2.1
sentry-sdk==2.52.0
setproctitle==1.3.7
shellingham==1.5.4
six==1.17.0
smmap==5.0.2
snac==1.2.1
sniffio==1.3.1
sortedcontainers==2.4.0
soundfile==0.13.1
soupsieve @ file:///home/conda/feedstock_root/build_artifacts/soupsieve_1756330469801/work
soxr==1.0.0
stack-data==0.6.3
starlette==0.52.1
supervisor==4.3.0
sympy==1.14.0
synthetic-data-kit==0.0.3
tabulate==0.9.0
tensorboard==2.20.0
tensorboard-data-server==0.7.2
termcolor==3.3.0
terminado==0.18.1
text-unidecode==1.3
threadpoolctl==3.6.0
tiktoken==0.12.0
timm==1.0.24
tinycss2==1.4.0
tokenizers==0.22.2
tomli==2.4.0
tomli_w==1.2.0
tomlkit==0.13.3
torch==2.9.0+cu128
torch-stoi==0.2.3
torch_c_dlpack_ext==0.1.5
torchao==0.14.0
torchaudio==2.9.0+cu128
torchcodec==0.10.0
torchelastic==0.2.2
torchvision==0.24.0+cu128
tornado==6.5.4
tqdm==4.67.3
trackio==0.15.0
traitlets==5.14.3
transformers==5.2.0
transformers-cfg==0.2.7
triton==3.5.0
triton_kernels @ file:///workspace/triton/python/triton_kernels
trl==0.23.1
truststore @ file:///home/conda/feedstock_root/build_artifacts/bld/rattler-build_truststore_1739009763/work
typeguard==4.4.4
typer==0.24.1
typer-slim==0.24.0
typing-inspection==0.4.2
typing_extensions==4.15.0
tyro==1.0.5
tzdata==2025.3
Unidecode==1.4.0
unsloth==2026.2.1
unsloth_zoo @ git+https://github.com/datta0/unsloth-zoo@5056d45b7fe76f81e16d47272a1eb4bb3ec48cb1
uri-template==1.3.0
urllib3==2.6.3
uroman==1.3.1.1
utilities==0.1.32
uv==0.9.3
uvicorn==0.40.0
uvloop==0.22.1
vllm==0.11.2
wandb==0.24.2
watchfiles==1.1.1
wcwidth==0.6.0
webcolors==25.10.0
webencodings==0.5.1
websocket-client==1.9.0
websockets==16.0
Werkzeug==3.1.5
widgetsnbextension==4.0.15
xformers==0.0.33.post1
xgrammar==0.1.25
xlsxwriter==3.2.9
xxhash==3.6.0
yarl==1.22.0
zipp==3.23.0
zstandard==0.25.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions