kathrinse / be_great

A novel approach for synthesizing tabular data using pretrained large language models
MIT License
276 stars 46 forks source link

AssertionError: Torch not compiled with CUDA enabled #9

Closed ayyucedemirbas closed 1 year ago

ayyucedemirbas commented 1 year ago

Hello,

I'm preparing a blog post about CTGANs and I want to cover this library too. I'm trying to generate synthetic data on my macbook m1 computer but I get this error message:

---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
Cell In[1], line 10
      8 model = GReaT(llm='distilgpt2', batch_size=16, epochs=2, save_steps=4)
      9 model.fit(df)
---> 10 synthetic_data = model.sample(n_samples=100)

File ~/mambaforge/envs/ctgan/lib/python3.9/site-packages/be_great/great.py:144, in GReaT.sample(self, n_samples, start_col, start_col_dist, temperature, k, max_length, device)
    141 great_start = self._get_start_sampler(start_col, start_col_dist)
    143 # Move model to device
--> 144 self.model.to(device)
    146 # Init empty DataFrame for the generated samples
    147 df_gen = pd.DataFrame(columns=self.columns)

File ~/mambaforge/envs/ctgan/lib/python3.9/site-packages/transformers/modeling_utils.py:1682, in PreTrainedModel.to(self, *args, **kwargs)
   1677     raise ValueError(
   1678         "`.to` is not supported for `8-bit` models. Please use the model as it is, since the"
   1679         " model has already been set to the correct devices and casted to the correct `dtype`."
   1680     )
   1681 else:
-> 1682     return super().to(*args, **kwargs)

File ~/mambaforge/envs/ctgan/lib/python3.9/site-packages/torch/nn/modules/module.py:989, in Module.to(self, *args, **kwargs)
    985         return t.to(device, dtype if t.is_floating_point() or t.is_complex() else None,
    986                     non_blocking, memory_format=convert_to_format)
    987     return t.to(device, dtype if t.is_floating_point() or t.is_complex() else None, non_blocking)
--> 989 return self._apply(convert)

File ~/mambaforge/envs/ctgan/lib/python3.9/site-packages/torch/nn/modules/module.py:641, in Module._apply(self, fn)
    639 def _apply(self, fn):
    640     for module in self.children():
--> 641         module._apply(fn)
    643     def compute_should_use_set_data(tensor, tensor_applied):
    644         if torch._has_compatible_shallow_copy_type(tensor, tensor_applied):
    645             # If the new tensor has compatible tensor type as the existing tensor,
    646             # the current behavior is to change the tensor in-place using `.data =`,
   (...)
    651             # global flag to let the user control whether they want the future
    652             # behavior of overwriting the existing tensor or not.

File ~/mambaforge/envs/ctgan/lib/python3.9/site-packages/torch/nn/modules/module.py:641, in Module._apply(self, fn)
    639 def _apply(self, fn):
    640     for module in self.children():
--> 641         module._apply(fn)
    643     def compute_should_use_set_data(tensor, tensor_applied):
    644         if torch._has_compatible_shallow_copy_type(tensor, tensor_applied):
    645             # If the new tensor has compatible tensor type as the existing tensor,
    646             # the current behavior is to change the tensor in-place using `.data =`,
   (...)
    651             # global flag to let the user control whether they want the future
    652             # behavior of overwriting the existing tensor or not.

File ~/mambaforge/envs/ctgan/lib/python3.9/site-packages/torch/nn/modules/module.py:664, in Module._apply(self, fn)
    660 # Tensors stored in modules are graph leaves, and we don't want to
    661 # track autograd history of `param_applied`, so we have to use
    662 # `with torch.no_grad():`
    663 with torch.no_grad():
--> 664     param_applied = fn(param)
    665 should_use_set_data = compute_should_use_set_data(param, param_applied)
    666 if should_use_set_data:

File ~/mambaforge/envs/ctgan/lib/python3.9/site-packages/torch/nn/modules/module.py:987, in Module.to.<locals>.convert(t)
    984 if convert_to_format is not None and t.dim() in (4, 5):
    985     return t.to(device, dtype if t.is_floating_point() or t.is_complex() else None,
    986                 non_blocking, memory_format=convert_to_format)
--> 987 return t.to(device, dtype if t.is_floating_point() or t.is_complex() else None, non_blocking)

File ~/mambaforge/envs/ctgan/lib/python3.9/site-packages/torch/cuda/__init__.py:221, in _lazy_init()
    217     raise RuntimeError(
    218         "Cannot re-initialize CUDA in forked subprocess. To use CUDA with "
    219         "multiprocessing, you must use the 'spawn' start method")
    220 if not hasattr(torch._C, '_cuda_getDeviceCount'):
--> 221     raise AssertionError("Torch not compiled with CUDA enabled")
    222 if _cudart is None:
    223     raise AssertionError(
    224         "libcudart functions unavailable. It looks like you have a broken build?")

AssertionError: Torch not compiled with CUDA enabled

How can I solve this problem?

Thank you so much!

unnir commented 1 year ago

Hi,

The error happens because your MacBook M1 computer doesn't have CUDA to use the special parts (GPU) of your computer that this library needs. As far as I know M1 does not support cuda yet... But PyTorch yes.

Your options are:

However, if there will be a need from the community we can add the M1 support to the new version of our package.