Getting Attribute Error while running provided code in Google Colab
Error: AttributeError: 'SNAC' object has no attribute 'device'
AttributeError Traceback (most recent call last)
/tmp/ipython-input-3-1462689041.py in <cell line: 0>()
123 # Hindi
124 text_hindi = "आज मैंने एक नई तकनीक के बारे में सीखा जो कृत्रिम बुद्धिमत्ता का उपयोग करके मानव जैसी आवाज़ उत्पन्न कर सकती है।"
--> 125 audio = generate_speech(text_hindi, speaker="kavya")
126 sf.write("output_hindi_kavya.wav", audio, 24000)
127
2 frames
/usr/local/lib/python3.11/dist-packages/torch/nn/modules/module.py in getattr(self, name)
1926 if name in modules:
1927 return modules[name]
-> 1928 raise AttributeError(
1929 f"'{type(self).name}' object has no attribute '{name}'"
1930 )
Just change
tensor = torch.tensor(lvl_codes, dtype=torch.int32, device=snac_model.device).unsqueeze(0)
to
tensor = torch.tensor(lvl_codes, dtype=torch.int32, device="cuda").unsqueeze(0)
or make changes in snac.py
Include the below line in __init__.py
self.device = torch.device("cuda" if torch.cuda.is_available() else "CPU")
device = next(snac_model.parameters()).device
tensor = torch.tensor(lvl_codes, dtype=torch.int32, device=device).unsqueeze(0)
try this