Skip to content

can not import 'sync_gpu' #1792

@hhchang0210

Description

@hhchang0210

System Info

python -m bitsandbytes
=================== bitsandbytes v0.48.2 ===================
Platform: Linux-6.6.105+-x86_64-with-glibc2.35
libc: glibc-2.35
Python: 3.12.12
PyTorch: 2.8.0+cu126
CUDA: 12.6
HIP: N/A
XPU: N/A
Related packages:
accelerate: 1.11.0
diffusers: 0.35.2
numpy: 2.0.2
pip: 24.1.2
peft: 0.9.0
safetensors: 0.6.2
transformers: 4.57.1
triton: 3.4.0
trl: not found

PyTorch settings found: CUDA_VERSION=126, Highest Compute Capability: (7, 5).
Checking that the library is importable and CUDA is callable...
SUCCESS!

Reproduction

I tried to run the following code on Colab:

import os
import sys
import argparse
import json
import warnings
import logging
warnings.filterwarnings("ignore")

import torch
import torch.nn as nn
import bitsandbytes as bnb
from datasets import load_dataset, load_from_disk
import transformers, datasets
from peft import PeftModel
from colorama import *

from tqdm import tqdm
from transformers import AutoTokenizer, AutoConfig, AutoModelForCausalLM, BitsAndBytesConfig
from transformers import GenerationConfig
from peft import (
prepare_model_for_int8_training,
LoraConfig,
get_peft_model,
get_peft_model_state_dict,
prepare_model_for_kbit_training
)

The error showed

ImportError Traceback (most recent call last)
/tmp/ipython-input-2251204960.py in <cell line: 0>()
11 import torch
12 import torch.nn as nn
---> 13 import bitsandbytes as bnb
14 from datasets import load_dataset, load_from_disk
15 import transformers, datasets

5 frames/usr/local/lib/python3.12/dist-packages/bitsandbytes/init.py in
18 from .backends.cpu import ops as cpu_ops
19 from .backends.default import ops as default_ops
---> 20 from .nn import modules
21 from .optim import adam
22

/usr/local/lib/python3.12/dist-packages/bitsandbytes/nn/init.py in
3 # This source code is licensed under the MIT license found in the
4 # LICENSE file in the root directory of this source tree.
----> 5 from .modules import (
6 Embedding,
7 Embedding4bit,

/usr/local/lib/python3.12/dist-packages/bitsandbytes/nn/modules.py in
14 from bitsandbytes.cextension import HIP_ENVIRONMENT
15 from bitsandbytes.functional import QuantState
---> 16 from bitsandbytes.optim import GlobalOptimManager
17 from bitsandbytes.utils import INVERSE_LINEAR_8BIT_WEIGHTS_FORMAT_MAPPING, OutlierTracer
18

/usr/local/lib/python3.12/dist-packages/bitsandbytes/optim/init.py in
4 # LICENSE file in the root directory of this source tree.
5
----> 6 from .adagrad import Adagrad, Adagrad8bit, Adagrad32bit
7 from .adam import Adam, Adam8bit, Adam32bit, PagedAdam, PagedAdam8bit, PagedAdam32bit
8 from .adamw import (

/usr/local/lib/python3.12/dist-packages/bitsandbytes/optim/adagrad.py in
3 # This source code is licensed under the MIT license found in the
4 # LICENSE file in the root directory of this source tree.
----> 5 from bitsandbytes.optim.optimizer import Optimizer1State
6
7

/usr/local/lib/python3.12/dist-packages/bitsandbytes/optim/optimizer.py in
11
12 import bitsandbytes.functional as F
---> 13 from bitsandbytes.utils import sync_gpu
14
15

ImportError: cannot import name 'sync_gpu' from 'bitsandbytes.utils' (/usr/local/lib/python3.12/dist-packages/bitsandbytes/utils.py)

Any suggestions? Thank you.

"Open Examples" button below.

Open Examples

Expected behavior

run the code successfully.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions