강의

멘토링

로드맵

Inflearn brand logo image

인프런 커뮤니티 질문&답변

황승현님의 프로필 이미지
황승현

작성한 질문수

딥러닝 CNN 완벽 가이드 - Pytorch 버전

Trainer에 Running 평균 Loss를 구현하기

Attribute Error(Frame Work 3번째 강의)

작성

·

17

0

'''
질문 내용
강의 수강하며 따로 코드 수정없이 실행해보며 이해해보는 중입니다. 아래와 같은 에러가 나서 수정해보고자 하는데 에러 해결이 안되어서 여쭤봅니다.

상기의 
'''

######### 실행 코드
from torch.optim import Adam

BATCH_SIZE = 32
INPUT_SIZE = 28

# train_loader = DataLoader(train_data, batch_size=BATCH_SIZE, shuffle=True, num_workers=4 )
# val_loader = DataLoader(val_data, batch_size=BATCH_SIZE, shuffle=False, num_workers=4)

# model, device, optimizer, loss 함수 생성.
model = create_simple_linear_model(input_size=INPUT_SIZE, num_classes=10)
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
optimizer = Adam(model.parameters(), lr=0.001)
loss_fn = nn.CrossEntropyLoss()

# Trainer 객체 생성. 
trainer = Trainer_01(model=model, loss_fn=loss_fn, optimizer=optimizer, train_loader=train_loader,
                 val_loader=val_loader, device=device)

#fit() 을 호출하여 학습과 검증을 epochs 수 만큼 반복 수행. 
trainer.fit(epochs=10)


########### 에러내용
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/tmp/ipykernel_36/3815854863.py in <cell line: 0>()
      8 model = create_simple_linear_model(input_size=INPUT_SIZE, num_classes=10)
      9 device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
---> 10 optimizer = Adam(model.parameters(), lr=0.001)
     11 loss_fn = nn.CrossEntropyLoss()
     12 

/usr/local/lib/python3.11/dist-packages/torch/optim/adam.py in init(self, params, lr, betas, eps, weight_decay, amsgrad, foreach, maximize, capturable, differentiable, fused)
     97             fused=fused,
     98         )
---> 99         super().__init__(params, defaults)
    100 
    101         if fused:

/usr/local/lib/python3.11/dist-packages/torch/optim/optimizer.py in init(self, params, defaults)
    375 
    376         for param_group in param_groups:
--> 377             self.add_param_group(cast(dict, param_group))
    378 
    379         # Allows cudagraph_capture_health_check to rig a poor man's TORCH_WARN_ONCE in python,

/usr/local/lib/python3.11/dist-packages/torch/_compile.py in inner(*args, **kwargs)
     25             disable_fn = getattr(fn, "__dynamo_disable", None)
     26             if disable_fn is None:
---> 27                 import torch._dynamo
     28 
     29                 disable_fn = torch._dynamo.disable(fn, recursive)

/usr/local/lib/python3.11/dist-packages/torch/_dynamo/__init__.py in <module>
      1 import torch
      2 
----> 3 from . import convert_frame, eval_frame, resume_execution
      4 from .backends.registry import list_backends, lookup_backend, register_backend
      5 from .callback import callback_handler, on_compile_end, on_compile_start

/usr/local/lib/python3.11/dist-packages/torch/_dynamo/convert_frame.py in <module>
     31 from torch._C._dynamo.guards import GlobalStateGuard
     32 from torch._dynamo.distributed import get_compile_pg
---> 33 from torch._dynamo.symbolic_convert import TensorifyState
     34 from torch._guards import compile_context, CompileContext, CompileId, tracing
     35 from torch._logging import structured

/usr/local/lib/python3.11/dist-packages/torch/_dynamo/symbolic_convert.py in <module>
     28 from torch._guards import tracing, TracingContext
     29 
---> 30 from . import config, exc, logging as torchdynamo_logging, trace_rules, variables
     31 from .bytecode_analysis import (
     32     get_indexof,

/usr/local/lib/python3.11/dist-packages/torch/_dynamo/trace_rules.py in <module>
   3264         "torch.distributed._composable.replicate",
   3265     }
-> 3266     if not torch._dynamo.config.skip_fsdp_hooks:
   3267         LEGACY_MOD_INLINELIST.add("torch.distributed.fsdp._fully_shard")
   3268 

AttributeError: partially initialized module 'torch._dynamo' has no attribute 'config' (most likely due to a circular import)

답변 1

0

권 철민님의 프로필 이미지
권 철민
지식공유자

안녕하십니까,

일단 원본 실습 코드를 그대로 사용하고 계신 건가요? 저는 해당 오류가 발생하지 않습니다.

그리고 오류 부분을 보면

optimizer = Adam(model.parameters(), lr=0.001)

에서 아래와 같이 import가 되지 않고 중복으로 되어 있는 부분이 있는지 확인 부탁드립니다.

from torch.optim import Adam

그런 부분이 없으시다면 다시 원본 실습 코드를 강의 자료에서 다운로드 받으셔서 재 수행 부탁드립니다.

감사합니다.

 

 

황승현님의 프로필 이미지
황승현
질문자

저도 주신 코드를 그대로 사용중에 에러가 발생하여 슬픕니다 ㅜㅜ

다시 다운로드 후 해결해보겠습니다! 감사합니다.

황승현님의 프로필 이미지
황승현

작성한 질문수

질문하기