[BUG] LightGCN model raises AttributeError: np.mat was removed in NumPy 2.0

Author: 14790897Created May 16, 2026Updated May 16, 2026
Labelsbug

Description

When running the LightGCN model from recommenders.models.deeprec, the following error occurs:

AttributeError: `np.mat` was removed in the NumPy 2.0 release. Use `np.asmatrix` instead.

The error happens at line 205 in lightgcn.py, where np.mat() is called. This function has been removed in NumPy 2.0, causing initialization failure.

In which platform does it happen?

Kaggle / Local environment with NumPy ≥ 2.0 and latest recommenders.

How do we replicate the issue?

A full reproducible notebook with complete error traceback is available here: https://www.kaggle.com/code/liuweiq/lightgcn-recommenders?scriptVersionId=319725522

Steps:

  1. Install latest recommenders .
  2. Run the LightGCN initialization code in the notebook.
  3. The error appears when creating the LightGCN model.

Expected behavior (i.e. solution)

Replace np.mat with np.asmatrix in line 205 of
recommenders/models/deeprec/models/graphrec/lightgcn.py.

Willingness to contribute

  • Yes, I can contribute for this issue independently.
  • Yes, I can contribute for this issue with guidance from Recommenders community.
  • No, I cannot contribute at this time.

Other Comments

This compatibility issue blocks LightGCN usage for all NumPy 2.0+ users. The fix is minimal and does not change existing logic. A quick user workaround is adding:

import numpy as np
np.mat = np.asmatrix

before importing/initializing LightGCN.

Source: recommenders-team/recommenders