728x90 반응형 전체 글50 Hook 메커니즘 PyTorch Hook 간단 정리훅(Hook)은 PyTorch에서 모델의 내부 동작을 관찰하고 수정할 수 있게 해주는 기능입니다. 1. 모듈 Hook 기본Forward Hook (출력 확인/수정)import torchimport torch.nn as nn# 간단한 모델model = nn.Linear(5, 2)# 출력값 저장 함수outputs = {}def save_output(name): def hook(module, input, output): outputs[name] = output # 출력값 저장 return hook# 훅 등록하기handle = model.register_forward_hook(save_output('linear'))# 모델 실행x = torch.randn.. 2025. 3. 24. PyTorch에서 모델이나 레이어 호출 PyTorch 모델 호출 문법 정리PyTorch에서 모델이나 레이어를 호출할 때 알아두면 좋은 내용을 깔끔하게 정리해드립니다.1. 기본 호출 메커니즘# 정의class MyModel(nn.Module): def __init__(self): super().__init__() self.layer = nn.Linear(10, 5) def forward(self, x): return self.layer(x)# 사용model = MyModel()output = model(input_tensor) # model.forward(input_tensor)가 자동으로 호출됨작동 원리:model(input_tensor)는 내부적으로 model.__call__(input_ten.. 2025. 3. 24. [1] Modeling Task Relationships in Multi-task Learning with Multi-gate Mixture-of-Experts ContributionThey propose a novel Multi-gate Mixture-of-Experts model which explicitly models task relationships.They conduct control experiments on synthetic data. They report how task relatedness affects training dynamics in multi-task learning and how MMoE improves both model expressiveness and trainability.They conduct experiments on real benchmark data and a large-scale production recommenda.. 2025. 3. 23. offsets 메커니즘 EmbeddingLayer의 offsets 메커니즘 상세 설명offsets 메커니즘은 이 클래스의 가장 핵심적인 부분이며, 여러 필드의 범주형 특성을 하나의 임베딩 테이블에서 충돌 없이 관리하기 위한 기법입니다. 단계별로 자세히 설명해드리겠습니다. # ref: layers.py in https://github.com/morningsky/multi_task_learningclass EmbeddingLayer(torch.nn.Module): def __init__(self, field_dims, embed_dim): super().__init__() self.embedding = torch.nn.Embedding(sum(field_dims), embed_dim) .. 2025. 3. 23. 이전 1 2 3 4 ··· 13 다음 728x90 반응형