C:\Users\20834\anaconda3\envs\ChatGLM-6B-new\python.exe F:\FL-bench\data\generate_data.py -d cifar10 -a 0.1 -cn 100
Traceback (most recent call last):
File "F:\FL-bench\data\generate_data.py", line 16, in
from utils.schemes import (
File "F:\FL-bench\data\utils\schemes_init_.py", line 5, in
from .semantic import semantic_partition
File "F:\FL-bench\data\utils\schemes\semantic.py", line 22, in
from src.config.utils import get_best_device
File "F:\FL-bench\src\config\utils.py", line 69, in
src: Union[OrderedDict[str, torch.Tensor], torch.nn.Module],
TypeError: 'type' object is not subscriptable
\FL-bench\src\config\utils.py
def trainable_params(
src: Union[OrderedDict[str, torch.Tensor], torch.nn.Module],
detach=False,
requires_name=False,
) -> Union[List[torch.Tensor], Tuple[List[torch.Tensor], List[str]]]:
It seems like you're encountering a TypeError, which says 'type' object is not subscriptable
. This error is most often raised when you are trying to treat a class or a type like a list or dictionary.
Your error seems to be related to this line:
src: Union[OrderedDict[str, torch.Tensor], torch.nn.Module],
The problem here is that Python cannot interpret the code as it's supposed to. The syntax you've used here is typical of Python 3.8+ (PEP 585), where you can directly use built-in types like list
, tuple
, dict
for type hinting.
However, if you're using a version of Python prior to 3.8, you'll need to import these types from the typing
module. For Python 3.7 or below, your line of code should look something like:
from typing import Union, List, Tuple, OrderedDict
from torch import Tensor
src: Union[OrderedDict[str, Tensor], torch.nn.Module],
Please verify the Python version you're using. If you're using Python 3.7 or below, consider upgrading your Python to 3.8+ to take advantage of the PEP 585 features. Otherwise, you'll need to import OrderedDict
from typing
.
fix bug TypeError: 'type' object is not subscriptable add the following source to file \FL-bench\src\config\utils.py
from typing import Union, List, Tuple, OrderedDict