andrecornman commited on
Commit
2e685a7
·
verified ·
1 Parent(s): 0662425

Upload FlashPPI model

Browse files
Files changed (45) hide show
  1. claude-1000/-home-ubuntu-ppi-project/5a87a0cd-6802-4ac5-a708-29b2bf7ea563/tasks/a07e7799acd8be342.output +0 -0
  2. config.json +25 -0
  3. configuration_flashppi.py +44 -0
  4. data.mdb +0 -0
  5. glm_tokenizer.py +48 -0
  6. lock.mdb +0 -0
  7. model.safetensors +3 -0
  8. modeling_flashppi.py +557 -0
  9. special_tokens_map.json +44 -0
  10. tmp1non0gt5/__pycache__/_remote_module_non_scriptable.cpython-312.pyc +0 -0
  11. tmp1non0gt5/_remote_module_non_scriptable.py +81 -0
  12. tmp38o1kqky/__pycache__/_remote_module_non_scriptable.cpython-312.pyc +0 -0
  13. tmp38o1kqky/_remote_module_non_scriptable.py +81 -0
  14. tmp69csjip6/__pycache__/_remote_module_non_scriptable.cpython-312.pyc +0 -0
  15. tmp69csjip6/_remote_module_non_scriptable.py +81 -0
  16. tmp9hzp29qv/__pycache__/_remote_module_non_scriptable.cpython-312.pyc +0 -0
  17. tmp9hzp29qv/_remote_module_non_scriptable.py +81 -0
  18. tmp_j0mzuvp/__pycache__/_remote_module_non_scriptable.cpython-312.pyc +0 -0
  19. tmp_j0mzuvp/_remote_module_non_scriptable.py +81 -0
  20. tmpd760ylpb/__pycache__/_remote_module_non_scriptable.cpython-312.pyc +0 -0
  21. tmpd760ylpb/_remote_module_non_scriptable.py +81 -0
  22. tmpdxfzs37c/__pycache__/_remote_module_non_scriptable.cpython-312.pyc +0 -0
  23. tmpdxfzs37c/_remote_module_non_scriptable.py +81 -0
  24. tmpf5f7c_r3/__pycache__/_remote_module_non_scriptable.cpython-312.pyc +0 -0
  25. tmpf5f7c_r3/_remote_module_non_scriptable.py +81 -0
  26. tmpiw5dwlcx/__pycache__/_remote_module_non_scriptable.cpython-312.pyc +0 -0
  27. tmpiw5dwlcx/_remote_module_non_scriptable.py +81 -0
  28. tmpnkix_nz4/__pycache__/_remote_module_non_scriptable.cpython-312.pyc +0 -0
  29. tmpnkix_nz4/_remote_module_non_scriptable.py +81 -0
  30. tmpp33g8q8r/__pycache__/_remote_module_non_scriptable.cpython-312.pyc +0 -0
  31. tmpp33g8q8r/_remote_module_non_scriptable.py +81 -0
  32. tmppbcdn8h9/__pycache__/_remote_module_non_scriptable.cpython-312.pyc +0 -0
  33. tmppbcdn8h9/_remote_module_non_scriptable.py +81 -0
  34. tmpqiqrdevn/__pycache__/_remote_module_non_scriptable.cpython-312.pyc +0 -0
  35. tmpqiqrdevn/_remote_module_non_scriptable.py +81 -0
  36. tmpqpwscwjm/__pycache__/_remote_module_non_scriptable.cpython-312.pyc +0 -0
  37. tmpqpwscwjm/_remote_module_non_scriptable.py +81 -0
  38. tmptu2tppnl/__pycache__/_remote_module_non_scriptable.cpython-312.pyc +0 -0
  39. tmptu2tppnl/_remote_module_non_scriptable.py +81 -0
  40. tmpvkx5qgfg/__pycache__/_remote_module_non_scriptable.cpython-312.pyc +0 -0
  41. tmpvkx5qgfg/_remote_module_non_scriptable.py +81 -0
  42. tmpxk_w0eue/__pycache__/_remote_module_non_scriptable.cpython-312.pyc +0 -0
  43. tmpxk_w0eue/_remote_module_non_scriptable.py +81 -0
  44. tokenizer.json +133 -0
  45. tokenizer_config.json +84 -0
claude-1000/-home-ubuntu-ppi-project/5a87a0cd-6802-4ac5-a708-29b2bf7ea563/tasks/a07e7799acd8be342.output ADDED
The diff for this file is too large to render. See raw diff
 
config.json ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "FlashPPIModel"
4
+ ],
5
+ "clip_embed_dim": 1024,
6
+ "contact_embed_dim": 1280,
7
+ "contact_num_heads": 8,
8
+ "contact_transformer_depth": 2,
9
+ "dtype": "float32",
10
+ "max_position_embeddings": 1024,
11
+ "model_type": "flashppi",
12
+ "plm_depth": 33,
13
+ "plm_dim": 1280,
14
+ "plm_ffn_dim_multiplier": null,
15
+ "plm_heads": 20,
16
+ "plm_norm_eps": 1e-05,
17
+ "plm_swiglu_multiple_of": 256,
18
+ "plm_vocab_size": 37,
19
+ "transformers_version": "4.57.3",
20
+ "use_flash_attention": true,
21
+ "auto_map": {
22
+ "AutoConfig": "configuration_flashppi.FlashPPIConfig",
23
+ "AutoModel": "modeling_flashppi.FlashPPIModel"
24
+ }
25
+ }
configuration_flashppi.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """FlashPPI model configuration."""
2
+
3
+ from transformers import PretrainedConfig
4
+
5
+
6
+ class FlashPPIConfig(PretrainedConfig):
7
+
8
+ model_type = "flashppi"
9
+
10
+ def __init__(
11
+ self,
12
+ # gLM2 backbone config (defaults match gLM2_650M)
13
+ plm_dim: int = 1280,
14
+ plm_depth: int = 33,
15
+ plm_heads: int = 20,
16
+ plm_vocab_size: int = 37,
17
+ plm_norm_eps: float = 1e-5,
18
+ plm_swiglu_multiple_of: int = 256,
19
+ plm_ffn_dim_multiplier: float = None,
20
+ # FlashPPI head config
21
+ clip_embed_dim: int = 1024,
22
+ contact_embed_dim: int = 1280,
23
+ contact_num_heads: int = 8,
24
+ contact_transformer_depth: int = 2,
25
+ max_position_embeddings: int = 512,
26
+ use_flash_attention: bool = True,
27
+ **kwargs
28
+ ):
29
+ super().__init__(**kwargs)
30
+ # gLM2 config
31
+ self.plm_dim = plm_dim
32
+ self.plm_depth = plm_depth
33
+ self.plm_heads = plm_heads
34
+ self.plm_vocab_size = plm_vocab_size
35
+ self.plm_norm_eps = plm_norm_eps
36
+ self.plm_swiglu_multiple_of = plm_swiglu_multiple_of
37
+ self.plm_ffn_dim_multiplier = plm_ffn_dim_multiplier
38
+ # FlashPPI config
39
+ self.clip_embed_dim = clip_embed_dim
40
+ self.contact_embed_dim = contact_embed_dim
41
+ self.contact_num_heads = contact_num_heads
42
+ self.contact_transformer_depth = contact_transformer_depth
43
+ self.max_position_embeddings = max_position_embeddings
44
+ self.use_flash_attention = use_flash_attention
data.mdb ADDED
Binary file (8.19 kB). View file
 
glm_tokenizer.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from tokenizers import Tokenizer
2
+ from tokenizers.models import BPE
3
+ from transformers import PreTrainedTokenizerFast
4
+
5
+
6
+ class gLM2Tokenizer(PreTrainedTokenizerFast):
7
+
8
+ VOCAB = [
9
+ "<cls>", "<pad>", "<eos>", "<unk>",
10
+ "L", "A", "G", "V", "S", "E", "R", "T", "I", "D", "P", "K",
11
+ "Q", "N", "F", "Y", "M", "H", "W", "C", "X", "B", "U", "Z",
12
+ "O", "a", "t", "c", "g", "<+>", "<->", "<mask>", "<sep>",
13
+ ]
14
+
15
+ def __init__(
16
+ self,
17
+ unk_token="<unk>",
18
+ cls_token="<cls>",
19
+ pad_token="<pad>",
20
+ mask_token="<mask>",
21
+ eos_token="<eos>",
22
+ sep_token="<sep>",
23
+ pos_token="<+>",
24
+ neg_token="<->",
25
+ **kwargs,
26
+ ):
27
+ all_tokens = self.VOCAB
28
+ token_to_id = {tok: ind for ind, tok in enumerate(all_tokens)}
29
+
30
+ bpe = BPE(token_to_id, merges=[], unk_token=str(unk_token))
31
+ tokenizer = Tokenizer(bpe)
32
+ special_tokens = [cls_token, pad_token,
33
+ mask_token, eos_token, sep_token, pos_token, neg_token]
34
+
35
+ tokenizer.add_special_tokens(
36
+ special_tokens,
37
+ )
38
+
39
+ super().__init__(
40
+ tokenizer_object=tokenizer,
41
+ unk_token=unk_token,
42
+ cls_token=cls_token,
43
+ pad_token=pad_token,
44
+ mask_token=mask_token,
45
+ eos_token=eos_token,
46
+ sep_token=sep_token,
47
+ **kwargs,
48
+ )
lock.mdb ADDED
Binary file (8.19 kB). View file
 
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2d730369e54cd83c634aaa8d3b6d0adaf23ed8034483c7f1e2b242b516b94ac1
3
+ size 2931379208
modeling_flashppi.py ADDED
@@ -0,0 +1,557 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import torch.nn as nn
3
+ import torch.nn.functional as F
4
+ from dataclasses import dataclass
5
+ from typing import Optional, Tuple, Union
6
+ from einops import rearrange, repeat
7
+ from torch.utils.checkpoint import checkpoint
8
+ from transformers import PreTrainedModel
9
+ from transformers.modeling_outputs import ModelOutput
10
+
11
+ from .configuration_flashppi import FlashPPIConfig
12
+
13
+ # Detect Flash Attention installation
14
+ try:
15
+ from flash_attn.layers.rotary import apply_rotary_emb_func
16
+ from flash_attn import flash_attn_varlen_kvpacked_func
17
+ from flash_attn.bert_padding import pad_input, unpad_input
18
+ FLASH_ATTN_AVAILABLE = True
19
+ except ImportError:
20
+ FLASH_ATTN_AVAILABLE = False
21
+ unpad_input = pad_input = apply_rotary_emb_func = None
22
+ flash_attn_varlen_kvpacked_func = None
23
+
24
+ def swiglu(x, y):
25
+ return F.silu(x) * y
26
+
27
+ class RMSNorm(nn.Module):
28
+ """RMSNorm without variance_epsilon buffer for checkpoint compatibility."""
29
+ def __init__(self, dim, eps=1e-6):
30
+ super().__init__()
31
+ self.weight = nn.Parameter(torch.ones(dim))
32
+ self.eps = eps
33
+
34
+ def forward(self, hidden_states):
35
+ input_dtype = hidden_states.dtype
36
+ hidden_states = hidden_states.to(torch.float32)
37
+ variance = hidden_states.pow(2).mean(-1, keepdim=True)
38
+ hidden_states = hidden_states * torch.rsqrt(variance + self.eps)
39
+ return (self.weight * hidden_states).to(input_dtype)
40
+
41
+ @dataclass
42
+ class FlashPPIOutput(ModelOutput):
43
+ """Output type for FlashPPI model.
44
+
45
+ Args:
46
+ contact_map: (B, L1, L2) contact probabilities between residue pairs.
47
+ contact_score: (B,) maximum contact probability per pair.
48
+ clip_embed1: (B, D) CLIP embedding for first protein.
49
+ clip_embed2: (B, D) CLIP embedding for second protein.
50
+ clip_score: (B,) CLIP similarity score (cosine similarity).
51
+ """
52
+ contact_map: Optional[torch.FloatTensor] = None
53
+ contact_score: Optional[torch.FloatTensor] = None
54
+ clip_embed1: Optional[torch.FloatTensor] = None
55
+ clip_embed2: Optional[torch.FloatTensor] = None
56
+ clip_score: Optional[torch.FloatTensor] = None
57
+
58
+
59
+ def rotate_half(x, interleaved=False):
60
+ if not interleaved:
61
+ x1, x2 = x.chunk(2, dim=-1)
62
+ return torch.cat((-x2, x1), dim=-1)
63
+ else:
64
+ x1, x2 = x[..., ::2], x[..., 1::2]
65
+ return rearrange(torch.stack((-x2, x1), dim=-1), "... d two -> ... (d two)", two=2)
66
+
67
+
68
+ def apply_rotary_emb_torch(x, cos, sin, interleaved=False, position_ids=None):
69
+ """Apply rotary embeddings using pure PyTorch."""
70
+ if position_ids is not None:
71
+ cos = cos[position_ids]
72
+ sin = sin[position_ids]
73
+ else:
74
+ cos = cos[:x.shape[1]]
75
+ sin = sin[:x.shape[1]]
76
+
77
+ if not interleaved:
78
+ cos = repeat(cos, "... d -> ... 1 (2 d)")
79
+ sin = repeat(sin, "... d -> ... 1 (2 d)")
80
+ else:
81
+ cos = repeat(cos, "... d -> ... 1 (d 2)")
82
+ sin = repeat(sin, "... d -> ... 1 (d 2)")
83
+
84
+ ro_dim = cos.shape[-1]
85
+ return torch.cat([
86
+ x[..., :ro_dim] * cos + rotate_half(x[..., :ro_dim], interleaved) * sin,
87
+ x[..., ro_dim:],
88
+ ], dim=-1)
89
+
90
+
91
+ class RotaryEmbedding(nn.Module):
92
+ """Rotary position embeddings with flash attention support."""
93
+
94
+ def __init__(self, dim: int, base: float = 10000.0, interleaved: bool = False, device=None):
95
+ super().__init__()
96
+ self.dim = dim
97
+ self.base = float(base)
98
+ self.interleaved = interleaved
99
+ inv_freq = 1.0 / (self.base ** (torch.arange(0, dim, 2, device=device, dtype=torch.float32) / dim))
100
+ self.register_buffer("inv_freq", inv_freq, persistent=False)
101
+ self._seq_len_cached = 0
102
+ self._cos_cached = None
103
+ self._sin_cached = None
104
+
105
+ def _update_cos_sin_cache(self, seqlen, device=None, dtype=None):
106
+ if seqlen > self._seq_len_cached or self._cos_cached is None or self._cos_cached.device != device:
107
+ self._seq_len_cached = seqlen
108
+ t = torch.arange(seqlen, device=device, dtype=torch.float32)
109
+ freqs = torch.outer(t, self.inv_freq.to(device=device, dtype=torch.float32))
110
+ self._cos_cached = torch.cos(freqs).to(dtype)
111
+ self._sin_cached = torch.sin(freqs).to(dtype)
112
+
113
+ def forward(
114
+ self,
115
+ q: torch.Tensor,
116
+ k: torch.Tensor,
117
+ cu_seqlens: Optional[torch.Tensor] = None,
118
+ max_seqlen: Optional[int] = None,
119
+ position_ids: Optional[torch.Tensor] = None,
120
+ ) -> Tuple[torch.Tensor, torch.Tensor]:
121
+ seqlen = q.shape[1] if max_seqlen is None else max_seqlen
122
+ self._update_cos_sin_cache(seqlen, device=q.device, dtype=q.dtype)
123
+
124
+ if FLASH_ATTN_AVAILABLE and cu_seqlens is not None:
125
+ q = apply_rotary_emb_func(
126
+ q, self._cos_cached, self._sin_cached,
127
+ interleaved=self.interleaved, inplace=True,
128
+ cu_seqlens=cu_seqlens, max_seqlen=max_seqlen,
129
+ )
130
+ k = apply_rotary_emb_func(
131
+ k, self._cos_cached, self._sin_cached,
132
+ interleaved=self.interleaved, inplace=True,
133
+ cu_seqlens=cu_seqlens, max_seqlen=max_seqlen,
134
+ )
135
+ else:
136
+ q = apply_rotary_emb_torch(q, self._cos_cached, self._sin_cached, self.interleaved, position_ids)
137
+ k = apply_rotary_emb_torch(k, self._cos_cached, self._sin_cached, self.interleaved, position_ids)
138
+ return q, k
139
+
140
+
141
+ class Attention(nn.Module):
142
+ """Multi-head attention with optional flash attention."""
143
+
144
+ def __init__(self, dim: int, num_heads: int, use_rope: bool = True):
145
+ super().__init__()
146
+ self.n_heads = num_heads
147
+ self.head_dim = dim // num_heads
148
+ self.wqkv = nn.Linear(dim, num_heads * self.head_dim * 3, bias=False)
149
+ self.wo = nn.Linear(num_heads * self.head_dim, dim, bias=False)
150
+ self.rotary_emb = RotaryEmbedding(self.head_dim) if use_rope else None
151
+
152
+ def forward(
153
+ self,
154
+ x: torch.Tensor,
155
+ cu_seqlens: Optional[torch.Tensor] = None,
156
+ max_seq_len: Optional[int] = None,
157
+ attention_mask: Optional[torch.Tensor] = None,
158
+ position_ids: Optional[torch.Tensor] = None,
159
+ ) -> torch.Tensor:
160
+ qkv = self.wqkv(x)
161
+
162
+ if cu_seqlens is not None and FLASH_ATTN_AVAILABLE:
163
+ # Flash attention path (unpadded)
164
+ total_seqlen = x.shape[0]
165
+ q, k, v = torch.split(qkv, self.n_heads * self.head_dim, dim=-1)
166
+ q = q.view(total_seqlen, self.n_heads, self.head_dim)
167
+ k = k.view(total_seqlen, self.n_heads, self.head_dim)
168
+ v = v.view(total_seqlen, self.n_heads, self.head_dim)
169
+
170
+ if self.rotary_emb is not None:
171
+ q, k = self.rotary_emb(q, k, cu_seqlens=cu_seqlens, max_seqlen=max_seq_len)
172
+
173
+ kv = torch.stack([k, v], 1)
174
+ output = flash_attn_varlen_kvpacked_func(
175
+ q, kv,
176
+ cu_seqlens_q=cu_seqlens, cu_seqlens_k=cu_seqlens,
177
+ max_seqlen_q=max_seq_len, max_seqlen_k=max_seq_len,
178
+ dropout_p=0.0, causal=False,
179
+ )
180
+ output = output.view(total_seqlen, self.n_heads * self.head_dim)
181
+ else:
182
+ # SDPA path (padded)
183
+ bsz, seqlen, _ = x.shape
184
+ q, k, v = torch.split(qkv, self.n_heads * self.head_dim, dim=-1)
185
+ q = q.view(bsz, seqlen, self.n_heads, self.head_dim)
186
+ k = k.view(bsz, seqlen, self.n_heads, self.head_dim)
187
+ v = v.view(bsz, seqlen, self.n_heads, self.head_dim)
188
+
189
+ if self.rotary_emb is not None:
190
+ q, k = self.rotary_emb(q, k, position_ids=position_ids)
191
+
192
+ q, k, v = q.transpose(1, 2), k.transpose(1, 2), v.transpose(1, 2)
193
+
194
+ attn_mask = None
195
+ if attention_mask is not None:
196
+ attn_mask = attention_mask.unsqueeze(1).unsqueeze(2).bool()
197
+
198
+ output = F.scaled_dot_product_attention(q, k, v, attn_mask=attn_mask, dropout_p=0.0, is_causal=False)
199
+ output = output.transpose(1, 2).contiguous().view(bsz, seqlen, self.n_heads * self.head_dim)
200
+
201
+ return self.wo(output)
202
+
203
+
204
+ class FeedForward(nn.Module):
205
+ """SwiGLU feedforward network."""
206
+
207
+ def __init__(self, dim: int, hidden_mult: float = 4.0, multiple_of: int = 256, ffn_dim_multiplier: float = None):
208
+ super().__init__()
209
+ hidden_dim = int(2 * dim * hidden_mult / 3)
210
+ if ffn_dim_multiplier is not None:
211
+ hidden_dim = int(ffn_dim_multiplier * hidden_dim)
212
+ hidden_dim = multiple_of * ((hidden_dim + multiple_of - 1) // multiple_of)
213
+ self.w1 = nn.Linear(dim, hidden_dim, bias=False)
214
+ self.w2 = nn.Linear(hidden_dim, dim, bias=False)
215
+ self.w3 = nn.Linear(dim, hidden_dim, bias=False)
216
+
217
+ def forward(self, x: torch.Tensor) -> torch.Tensor:
218
+ return self.w2(swiglu(self.w1(x), self.w3(x)))
219
+
220
+
221
+ class TransformerBlock(nn.Module):
222
+ """Pre-norm transformer block."""
223
+
224
+ def __init__(self, dim: int, num_heads: int, norm_eps: float = 1e-6,
225
+ multiple_of: int = 256, ffn_dim_multiplier: float = None, use_rope: bool = True):
226
+ super().__init__()
227
+ self.attention = Attention(dim, num_heads, use_rope)
228
+ self.feed_forward = FeedForward(dim, multiple_of=multiple_of, ffn_dim_multiplier=ffn_dim_multiplier)
229
+ self.attention_norm = RMSNorm(dim, eps=norm_eps)
230
+ self.ffn_norm = RMSNorm(dim, eps=norm_eps)
231
+
232
+ def forward(
233
+ self,
234
+ x: torch.Tensor,
235
+ cu_seqlens: Optional[torch.Tensor] = None,
236
+ max_seq_len: Optional[int] = None,
237
+ attention_mask: Optional[torch.Tensor] = None,
238
+ position_ids: Optional[torch.Tensor] = None,
239
+ ) -> torch.Tensor:
240
+ h = x + self.attention(self.attention_norm(x), cu_seqlens, max_seq_len, attention_mask, position_ids)
241
+ return h + self.feed_forward(self.ffn_norm(h))
242
+
243
+
244
+ class TransformerLayers(nn.Module):
245
+ """Stack of transformer blocks with optional flash attention."""
246
+
247
+ def __init__(self, dim: int, num_heads: int, depth: int, norm_eps: float = 1e-6,
248
+ multiple_of: int = 256, ffn_dim_multiplier: float = None, use_rope: bool = True):
249
+ super().__init__()
250
+ self.dim = dim
251
+ self.layers = nn.ModuleList([
252
+ TransformerBlock(dim, num_heads, norm_eps, multiple_of, ffn_dim_multiplier, use_rope)
253
+ for _ in range(depth)
254
+ ])
255
+ self.gradient_checkpointing = False
256
+
257
+ def forward(self, x: torch.Tensor, attention_mask: Optional[torch.Tensor] = None) -> torch.Tensor:
258
+ batch_size, seq_len = x.shape[:2]
259
+ cu_seqlens, max_seq_len_in_batch, indices, position_ids = None, None, None, None
260
+
261
+ if FLASH_ATTN_AVAILABLE and attention_mask is not None and not attention_mask.all():
262
+ x, indices, cu_seqlens, max_seq_len_in_batch, _ = unpad_input(x, attention_mask)
263
+ mask_for_layers = None
264
+ elif attention_mask is not None:
265
+ mask_long = attention_mask.long()
266
+ position_ids = (mask_long.cumsum(dim=1) - 1).clamp(min=0)
267
+ mask_for_layers = attention_mask
268
+ else:
269
+ mask_for_layers = None
270
+
271
+ for layer in self.layers:
272
+ if self.training and self.gradient_checkpointing:
273
+ x = checkpoint(layer, x, cu_seqlens, max_seq_len_in_batch, mask_for_layers, position_ids, use_reentrant=False)
274
+ else:
275
+ x = layer(x, cu_seqlens, max_seq_len_in_batch, mask_for_layers, position_ids)
276
+
277
+ if FLASH_ATTN_AVAILABLE and indices is not None:
278
+ x = pad_input(x, indices, batch_size, seq_len)
279
+
280
+ return x
281
+
282
+
283
+ class GLM2Backbone(nn.Module):
284
+ """gLM2 protein language model backbone."""
285
+
286
+ def __init__(self, config: FlashPPIConfig):
287
+ super().__init__()
288
+ self.config = config
289
+ self.tok_embeddings = nn.Embedding(config.plm_vocab_size, config.plm_dim)
290
+ self.encoder = TransformerLayers(
291
+ dim=config.plm_dim,
292
+ num_heads=config.plm_heads,
293
+ depth=config.plm_depth,
294
+ norm_eps=config.plm_norm_eps,
295
+ multiple_of=config.plm_swiglu_multiple_of,
296
+ ffn_dim_multiplier=config.plm_ffn_dim_multiplier,
297
+ use_rope=True,
298
+ )
299
+
300
+ def forward(self, input_ids: torch.Tensor, attention_mask: Optional[torch.Tensor] = None) -> torch.Tensor:
301
+ h = self.tok_embeddings(input_ids)
302
+ return self.encoder(h, attention_mask)
303
+
304
+
305
+ class MLPHead(nn.Module):
306
+ """SwiGLU MLP projection head."""
307
+
308
+ def __init__(self, in_dim: int, out_dim: int, hidden_mult: float = 2.0):
309
+ super().__init__()
310
+ hidden_dim = int(in_dim * hidden_mult)
311
+ self.w1 = nn.Linear(in_dim, hidden_dim, bias=False)
312
+ self.w2 = nn.Linear(hidden_dim, out_dim, bias=False)
313
+ self.w3 = nn.Linear(in_dim, hidden_dim, bias=False)
314
+
315
+ def forward(self, x: torch.Tensor) -> torch.Tensor:
316
+ return self.w2(F.silu(self.w1(x)) * self.w3(x))
317
+
318
+
319
+ class ContrastiveHead(nn.Module):
320
+ """CLIP-style contrastive head with mean pooling."""
321
+
322
+ def __init__(self, hidden_dim: int, embed_dim: int):
323
+ super().__init__()
324
+ self.head = MLPHead(hidden_dim, embed_dim)
325
+
326
+ def forward(self, residue_embeds: torch.Tensor, mask: torch.Tensor) -> torch.Tensor:
327
+ mask = mask.unsqueeze(-1).bool()
328
+ embeds = torch.where(mask, residue_embeds, 0.0)
329
+ embeds = embeds.sum(dim=1) / mask.sum(dim=1).float().clamp(min=1.0)
330
+ return F.normalize(self.head(embeds), dim=-1)
331
+
332
+
333
+ class ContactHead(nn.Module):
334
+ """Contact prediction head using cross-attention between protein pairs."""
335
+
336
+ def __init__(self, input_dim: int, contact_dim: int, num_heads: int = 8, depth: int = 2):
337
+ super().__init__()
338
+ self.num_heads = num_heads
339
+ self.head_dim = contact_dim // num_heads
340
+ assert contact_dim % num_heads == 0
341
+
342
+ self.segment_embed = nn.Embedding(2, input_dim)
343
+ nn.init.normal_(self.segment_embed.weight, std=0.02)
344
+
345
+ self.transformer = TransformerLayers(input_dim, num_heads, depth, use_rope=True)
346
+ self.norm = nn.LayerNorm(input_dim)
347
+ self.q_proj = nn.Linear(input_dim, contact_dim, bias=True)
348
+ self.k_proj = nn.Linear(input_dim, contact_dim, bias=True)
349
+ self.output_mix = nn.Linear(num_heads, 1)
350
+ nn.init.constant_(self.output_mix.bias, -3.0)
351
+ self.scale = self.head_dim ** -0.5
352
+
353
+ def forward(
354
+ self,
355
+ embed1: torch.Tensor,
356
+ embed2: torch.Tensor,
357
+ mask1: torch.Tensor,
358
+ mask2: torch.Tensor,
359
+ ) -> Tuple[torch.Tensor, torch.Tensor]:
360
+ B, L1, D = embed1.shape
361
+ _, L2, _ = embed2.shape
362
+
363
+ seg1 = self.segment_embed(torch.zeros(L1, device=embed1.device, dtype=torch.long))
364
+ seg2 = self.segment_embed(torch.ones(L2, device=embed1.device, dtype=torch.long))
365
+
366
+ x = torch.cat([embed1 + seg1.unsqueeze(0), embed2 + seg2.unsqueeze(0)], dim=1)
367
+ combined_mask = torch.cat([mask1, mask2], dim=1).bool() if mask1 is not None and mask2 is not None else None
368
+
369
+ x = self.transformer(x, attention_mask=combined_mask)
370
+
371
+ embed1 = self.norm(x[:, :L1, :])
372
+ embed2 = self.norm(x[:, L1:, :])
373
+
374
+ q = self.q_proj(embed1).view(B, L1, self.num_heads, self.head_dim).transpose(1, 2)
375
+ k = self.k_proj(embed2).view(B, L2, self.num_heads, self.head_dim).transpose(1, 2)
376
+
377
+ attn_logits = torch.matmul(q, k.transpose(-2, -1)) * self.scale
378
+ attn_logits = attn_logits.permute(0, 2, 3, 1).contiguous()
379
+ contact_logits = self.output_mix(attn_logits).squeeze(-1)
380
+
381
+ if mask1 is not None and mask2 is not None:
382
+ valid_mask = (mask1.unsqueeze(2) * mask2.unsqueeze(1)).bool()
383
+ else:
384
+ valid_mask = torch.ones_like(contact_logits, dtype=torch.bool)
385
+
386
+ return contact_logits, valid_mask
387
+
388
+
389
+ class FlashPPIPreTrainedModel(PreTrainedModel):
390
+ """Base class for FlashPPI models."""
391
+
392
+ config_class = FlashPPIConfig
393
+ base_model_prefix = "flashppi"
394
+ supports_gradient_checkpointing = True
395
+
396
+ def _init_weights(self, module):
397
+ if isinstance(module, nn.Linear):
398
+ nn.init.normal_(module.weight, std=0.02)
399
+ if module.bias is not None:
400
+ nn.init.zeros_(module.bias)
401
+ elif isinstance(module, nn.Embedding):
402
+ nn.init.normal_(module.weight, std=0.02)
403
+ elif isinstance(module, RotaryEmbedding):
404
+ # Re-calculate the frequencies using the module's stored attributes
405
+ inv_freq = 1.0 / (
406
+ module.base
407
+ ** (
408
+ torch.arange(0, module.dim, 2, device=module.inv_freq.device, dtype=torch.float32)
409
+ / module.dim
410
+ )
411
+ )
412
+ # Force the buffer to update
413
+ with torch.no_grad():
414
+ module.inv_freq.copy_(inv_freq)
415
+
416
+ class FlashPPIModel(FlashPPIPreTrainedModel):
417
+ """FlashPPI model."""
418
+
419
+ def __init__(self, config: FlashPPIConfig):
420
+ super().__init__(config)
421
+ self.config = config
422
+
423
+ # gLM2 backbone
424
+ self.plm = GLM2Backbone(config)
425
+
426
+ # CLIP heads (asymmetric for query/key)
427
+ self.head_q = ContrastiveHead(config.plm_dim, config.clip_embed_dim)
428
+ self.head_k = ContrastiveHead(config.plm_dim, config.clip_embed_dim)
429
+ self.logit_scale = nn.Parameter(torch.ones([]) * 2.6593) # ln(1/0.07)
430
+
431
+ # Contact prediction head
432
+ self.contact_head = ContactHead(
433
+ config.plm_dim,
434
+ config.contact_embed_dim,
435
+ num_heads=config.contact_num_heads,
436
+ depth=config.contact_transformer_depth,
437
+ )
438
+
439
+ self.post_init()
440
+
441
+ def encode_protein(
442
+ self,
443
+ input_ids: torch.Tensor,
444
+ attention_mask: Optional[torch.Tensor] = None,
445
+ ) -> torch.Tensor:
446
+ """Encode a protein sequence to residue-level embeddings.
447
+
448
+ Args:
449
+ input_ids: (B, L) token IDs from gLM2 tokenizer.
450
+ attention_mask: (B, L) attention mask.
451
+
452
+ Returns:
453
+ (B, L, plm_dim) residue embeddings.
454
+ """
455
+ return self.plm(input_ids, attention_mask)
456
+
457
+ def predict_contacts(
458
+ self,
459
+ embed1: torch.Tensor,
460
+ embed2: torch.Tensor,
461
+ mask1: torch.Tensor,
462
+ mask2: torch.Tensor,
463
+ ) -> Tuple[torch.Tensor, torch.Tensor]:
464
+ """Predict contact map from pre-computed residue embeddings.
465
+
466
+ This method is useful for efficient 2-stage inference where embeddings
467
+ are pre-computed and cached.
468
+
469
+ Args:
470
+ embed1: (B, L1, D) residue embeddings for protein 1.
471
+ embed2: (B, L2, D) residue embeddings for protein 2.
472
+ mask1: (B, L1) attention mask for protein 1.
473
+ mask2: (B, L2) attention mask for protein 2.
474
+
475
+ Returns:
476
+ contact_logits: (B, L1, L2) raw logits.
477
+ valid_mask: (B, L1, L2) mask for valid positions.
478
+ """
479
+ return self.contact_head(embed1, embed2, mask1, mask2)
480
+
481
+ def forward(
482
+ self,
483
+ input_ids1: torch.Tensor,
484
+ input_ids2: torch.Tensor,
485
+ attention_mask1: Optional[torch.Tensor] = None,
486
+ attention_mask2: Optional[torch.Tensor] = None,
487
+ return_dict: bool = True,
488
+ ) -> Union[Tuple, FlashPPIOutput]:
489
+ """Forward pass for protein pair interaction prediction.
490
+
491
+ Args:
492
+ input_ids1: (B, L1) token IDs for protein 1.
493
+ input_ids2: (B, L2) token IDs for protein 2.
494
+ attention_mask1: (B, L1) attention mask for protein 1.
495
+ attention_mask2: (B, L2) attention mask for protein 2.
496
+ return_dict: Whether to return a FlashPPIOutput or tuple.
497
+
498
+ Returns:
499
+ FlashPPIOutput with contact predictions and CLIP embeddings.
500
+ """
501
+ B = input_ids1.shape[0]
502
+ L1, L2 = input_ids1.shape[1], input_ids2.shape[1]
503
+
504
+ if attention_mask1 is None:
505
+ attention_mask1 = torch.ones_like(input_ids1)
506
+ if attention_mask2 is None:
507
+ attention_mask2 = torch.ones_like(input_ids2)
508
+
509
+ # Encode both proteins in a single batched PLM call for efficiency
510
+ # Pad to same length if needed
511
+ if L1 != L2:
512
+ max_len = max(L1, L2)
513
+ if L1 < max_len:
514
+ pad_len = max_len - L1
515
+ input_ids1 = F.pad(input_ids1, (0, pad_len), value=0)
516
+ attention_mask1 = F.pad(attention_mask1, (0, pad_len), value=0)
517
+ if L2 < max_len:
518
+ pad_len = max_len - L2
519
+ input_ids2 = F.pad(input_ids2, (0, pad_len), value=0)
520
+ attention_mask2 = F.pad(attention_mask2, (0, pad_len), value=0)
521
+
522
+ # Batch both sequences for single PLM forward pass
523
+ batched_input_ids = torch.cat([input_ids1, input_ids2], dim=0)
524
+ batched_attention_mask = torch.cat([attention_mask1, attention_mask2], dim=0)
525
+ batched_embeds = self.encode_protein(batched_input_ids, batched_attention_mask)
526
+
527
+ # Split and trim back to original lengths
528
+ residue_embeds1 = batched_embeds[:B, :L1, :]
529
+ residue_embeds2 = batched_embeds[B:, :L2, :]
530
+ attention_mask1 = attention_mask1[:, :L1]
531
+ attention_mask2 = attention_mask2[:, :L2]
532
+
533
+ # Contrastive embeddings
534
+ clip_embed1 = self.head_q(residue_embeds1, attention_mask1)
535
+ clip_embed2 = self.head_k(residue_embeds2, attention_mask2)
536
+ clip_score = (clip_embed1 * clip_embed2).sum(dim=-1)
537
+
538
+ # Contact prediction
539
+ contact_logits, valid_mask = self.contact_head(
540
+ residue_embeds1, residue_embeds2, attention_mask1, attention_mask2
541
+ )
542
+ contact_map = torch.sigmoid(contact_logits)
543
+
544
+ # Mask invalid positions before taking max
545
+ contact_map_masked = contact_map.masked_fill(~valid_mask, 0.0)
546
+ contact_score = contact_map_masked.flatten(1).max(dim=-1).values
547
+
548
+ if not return_dict:
549
+ return (contact_map, contact_score, clip_embed1, clip_embed2, clip_score)
550
+
551
+ return FlashPPIOutput(
552
+ contact_map=contact_map,
553
+ contact_score=contact_score,
554
+ clip_embed1=clip_embed1,
555
+ clip_embed2=clip_embed2,
556
+ clip_score=clip_score,
557
+ )
special_tokens_map.json ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cls_token": {
3
+ "content": "<cls>",
4
+ "lstrip": false,
5
+ "normalized": false,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "eos_token": {
10
+ "content": "<eos>",
11
+ "lstrip": false,
12
+ "normalized": false,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "mask_token": {
17
+ "content": "<mask>",
18
+ "lstrip": false,
19
+ "normalized": false,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ },
23
+ "pad_token": {
24
+ "content": "<pad>",
25
+ "lstrip": false,
26
+ "normalized": false,
27
+ "rstrip": false,
28
+ "single_word": false
29
+ },
30
+ "sep_token": {
31
+ "content": "<sep>",
32
+ "lstrip": false,
33
+ "normalized": false,
34
+ "rstrip": false,
35
+ "single_word": false
36
+ },
37
+ "unk_token": {
38
+ "content": "<unk>",
39
+ "lstrip": false,
40
+ "normalized": false,
41
+ "rstrip": false,
42
+ "single_word": false
43
+ }
44
+ }
tmp1non0gt5/__pycache__/_remote_module_non_scriptable.cpython-312.pyc ADDED
Binary file (2.61 kB). View file
 
tmp1non0gt5/_remote_module_non_scriptable.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import *
2
+
3
+ import torch
4
+ import torch.distributed.rpc as rpc
5
+ from torch import Tensor
6
+ from torch._jit_internal import Future
7
+ from torch.distributed.rpc import RRef
8
+ from typing import Tuple # pyre-ignore: unused import
9
+
10
+
11
+ module_interface_cls = None
12
+
13
+
14
+ def forward_async(self, *args, **kwargs):
15
+ args = (self.module_rref, self.device, self.is_device_map_set, *args)
16
+ kwargs = {**kwargs}
17
+ return rpc.rpc_async(
18
+ self.module_rref.owner(),
19
+ _remote_forward,
20
+ args,
21
+ kwargs,
22
+ )
23
+
24
+
25
+ def forward(self, *args, **kwargs):
26
+ args = (self.module_rref, self.device, self.is_device_map_set, *args)
27
+ kwargs = {**kwargs}
28
+ ret_fut = rpc.rpc_async(
29
+ self.module_rref.owner(),
30
+ _remote_forward,
31
+ args,
32
+ kwargs,
33
+ )
34
+ return ret_fut.wait()
35
+
36
+
37
+ _generated_methods = [
38
+ forward_async,
39
+ forward,
40
+ ]
41
+
42
+
43
+
44
+
45
+ def _remote_forward(
46
+ module_rref: RRef[module_interface_cls], device: str, is_device_map_set: bool, *args, **kwargs):
47
+ module = module_rref.local_value()
48
+ device = torch.device(device)
49
+
50
+ if device.type != "cuda":
51
+ return module.forward(*args, **kwargs)
52
+
53
+ # If the module is on a cuda device,
54
+ # move any CPU tensor in args or kwargs to the same cuda device.
55
+ # Since torch script does not support generator expression,
56
+ # have to use concatenation instead of
57
+ # ``tuple(i.to(device) if isinstance(i, Tensor) else i for i in *args)``.
58
+ args = (*args,)
59
+ out_args: Tuple[()] = ()
60
+ for arg in args:
61
+ arg = (arg.to(device),) if isinstance(arg, Tensor) else (arg,)
62
+ out_args = out_args + arg
63
+
64
+ kwargs = {**kwargs}
65
+ for k, v in kwargs.items():
66
+ if isinstance(v, Tensor):
67
+ kwargs[k] = kwargs[k].to(device)
68
+
69
+ if is_device_map_set:
70
+ return module.forward(*out_args, **kwargs)
71
+
72
+ # If the device map is empty, then only CPU tensors are allowed to send over wire,
73
+ # so have to move any GPU tensor to CPU in the output.
74
+ # Since torch script does not support generator expression,
75
+ # have to use concatenation instead of
76
+ # ``tuple(i.cpu() if isinstance(i, Tensor) else i for i in module.forward(*out_args, **kwargs))``.
77
+ ret: Tuple[()] = ()
78
+ for i in module.forward(*out_args, **kwargs):
79
+ i = (i.cpu(),) if isinstance(i, Tensor) else (i,)
80
+ ret = ret + i
81
+ return ret
tmp38o1kqky/__pycache__/_remote_module_non_scriptable.cpython-312.pyc ADDED
Binary file (2.61 kB). View file
 
tmp38o1kqky/_remote_module_non_scriptable.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import *
2
+
3
+ import torch
4
+ import torch.distributed.rpc as rpc
5
+ from torch import Tensor
6
+ from torch._jit_internal import Future
7
+ from torch.distributed.rpc import RRef
8
+ from typing import Tuple # pyre-ignore: unused import
9
+
10
+
11
+ module_interface_cls = None
12
+
13
+
14
+ def forward_async(self, *args, **kwargs):
15
+ args = (self.module_rref, self.device, self.is_device_map_set, *args)
16
+ kwargs = {**kwargs}
17
+ return rpc.rpc_async(
18
+ self.module_rref.owner(),
19
+ _remote_forward,
20
+ args,
21
+ kwargs,
22
+ )
23
+
24
+
25
+ def forward(self, *args, **kwargs):
26
+ args = (self.module_rref, self.device, self.is_device_map_set, *args)
27
+ kwargs = {**kwargs}
28
+ ret_fut = rpc.rpc_async(
29
+ self.module_rref.owner(),
30
+ _remote_forward,
31
+ args,
32
+ kwargs,
33
+ )
34
+ return ret_fut.wait()
35
+
36
+
37
+ _generated_methods = [
38
+ forward_async,
39
+ forward,
40
+ ]
41
+
42
+
43
+
44
+
45
+ def _remote_forward(
46
+ module_rref: RRef[module_interface_cls], device: str, is_device_map_set: bool, *args, **kwargs):
47
+ module = module_rref.local_value()
48
+ device = torch.device(device)
49
+
50
+ if device.type != "cuda":
51
+ return module.forward(*args, **kwargs)
52
+
53
+ # If the module is on a cuda device,
54
+ # move any CPU tensor in args or kwargs to the same cuda device.
55
+ # Since torch script does not support generator expression,
56
+ # have to use concatenation instead of
57
+ # ``tuple(i.to(device) if isinstance(i, Tensor) else i for i in *args)``.
58
+ args = (*args,)
59
+ out_args: Tuple[()] = ()
60
+ for arg in args:
61
+ arg = (arg.to(device),) if isinstance(arg, Tensor) else (arg,)
62
+ out_args = out_args + arg
63
+
64
+ kwargs = {**kwargs}
65
+ for k, v in kwargs.items():
66
+ if isinstance(v, Tensor):
67
+ kwargs[k] = kwargs[k].to(device)
68
+
69
+ if is_device_map_set:
70
+ return module.forward(*out_args, **kwargs)
71
+
72
+ # If the device map is empty, then only CPU tensors are allowed to send over wire,
73
+ # so have to move any GPU tensor to CPU in the output.
74
+ # Since torch script does not support generator expression,
75
+ # have to use concatenation instead of
76
+ # ``tuple(i.cpu() if isinstance(i, Tensor) else i for i in module.forward(*out_args, **kwargs))``.
77
+ ret: Tuple[()] = ()
78
+ for i in module.forward(*out_args, **kwargs):
79
+ i = (i.cpu(),) if isinstance(i, Tensor) else (i,)
80
+ ret = ret + i
81
+ return ret
tmp69csjip6/__pycache__/_remote_module_non_scriptable.cpython-312.pyc ADDED
Binary file (2.61 kB). View file
 
tmp69csjip6/_remote_module_non_scriptable.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import *
2
+
3
+ import torch
4
+ import torch.distributed.rpc as rpc
5
+ from torch import Tensor
6
+ from torch._jit_internal import Future
7
+ from torch.distributed.rpc import RRef
8
+ from typing import Tuple # pyre-ignore: unused import
9
+
10
+
11
+ module_interface_cls = None
12
+
13
+
14
+ def forward_async(self, *args, **kwargs):
15
+ args = (self.module_rref, self.device, self.is_device_map_set, *args)
16
+ kwargs = {**kwargs}
17
+ return rpc.rpc_async(
18
+ self.module_rref.owner(),
19
+ _remote_forward,
20
+ args,
21
+ kwargs,
22
+ )
23
+
24
+
25
+ def forward(self, *args, **kwargs):
26
+ args = (self.module_rref, self.device, self.is_device_map_set, *args)
27
+ kwargs = {**kwargs}
28
+ ret_fut = rpc.rpc_async(
29
+ self.module_rref.owner(),
30
+ _remote_forward,
31
+ args,
32
+ kwargs,
33
+ )
34
+ return ret_fut.wait()
35
+
36
+
37
+ _generated_methods = [
38
+ forward_async,
39
+ forward,
40
+ ]
41
+
42
+
43
+
44
+
45
+ def _remote_forward(
46
+ module_rref: RRef[module_interface_cls], device: str, is_device_map_set: bool, *args, **kwargs):
47
+ module = module_rref.local_value()
48
+ device = torch.device(device)
49
+
50
+ if device.type != "cuda":
51
+ return module.forward(*args, **kwargs)
52
+
53
+ # If the module is on a cuda device,
54
+ # move any CPU tensor in args or kwargs to the same cuda device.
55
+ # Since torch script does not support generator expression,
56
+ # have to use concatenation instead of
57
+ # ``tuple(i.to(device) if isinstance(i, Tensor) else i for i in *args)``.
58
+ args = (*args,)
59
+ out_args: Tuple[()] = ()
60
+ for arg in args:
61
+ arg = (arg.to(device),) if isinstance(arg, Tensor) else (arg,)
62
+ out_args = out_args + arg
63
+
64
+ kwargs = {**kwargs}
65
+ for k, v in kwargs.items():
66
+ if isinstance(v, Tensor):
67
+ kwargs[k] = kwargs[k].to(device)
68
+
69
+ if is_device_map_set:
70
+ return module.forward(*out_args, **kwargs)
71
+
72
+ # If the device map is empty, then only CPU tensors are allowed to send over wire,
73
+ # so have to move any GPU tensor to CPU in the output.
74
+ # Since torch script does not support generator expression,
75
+ # have to use concatenation instead of
76
+ # ``tuple(i.cpu() if isinstance(i, Tensor) else i for i in module.forward(*out_args, **kwargs))``.
77
+ ret: Tuple[()] = ()
78
+ for i in module.forward(*out_args, **kwargs):
79
+ i = (i.cpu(),) if isinstance(i, Tensor) else (i,)
80
+ ret = ret + i
81
+ return ret
tmp9hzp29qv/__pycache__/_remote_module_non_scriptable.cpython-312.pyc ADDED
Binary file (2.61 kB). View file
 
tmp9hzp29qv/_remote_module_non_scriptable.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import *
2
+
3
+ import torch
4
+ import torch.distributed.rpc as rpc
5
+ from torch import Tensor
6
+ from torch._jit_internal import Future
7
+ from torch.distributed.rpc import RRef
8
+ from typing import Tuple # pyre-ignore: unused import
9
+
10
+
11
+ module_interface_cls = None
12
+
13
+
14
+ def forward_async(self, *args, **kwargs):
15
+ args = (self.module_rref, self.device, self.is_device_map_set, *args)
16
+ kwargs = {**kwargs}
17
+ return rpc.rpc_async(
18
+ self.module_rref.owner(),
19
+ _remote_forward,
20
+ args,
21
+ kwargs,
22
+ )
23
+
24
+
25
+ def forward(self, *args, **kwargs):
26
+ args = (self.module_rref, self.device, self.is_device_map_set, *args)
27
+ kwargs = {**kwargs}
28
+ ret_fut = rpc.rpc_async(
29
+ self.module_rref.owner(),
30
+ _remote_forward,
31
+ args,
32
+ kwargs,
33
+ )
34
+ return ret_fut.wait()
35
+
36
+
37
+ _generated_methods = [
38
+ forward_async,
39
+ forward,
40
+ ]
41
+
42
+
43
+
44
+
45
+ def _remote_forward(
46
+ module_rref: RRef[module_interface_cls], device: str, is_device_map_set: bool, *args, **kwargs):
47
+ module = module_rref.local_value()
48
+ device = torch.device(device)
49
+
50
+ if device.type != "cuda":
51
+ return module.forward(*args, **kwargs)
52
+
53
+ # If the module is on a cuda device,
54
+ # move any CPU tensor in args or kwargs to the same cuda device.
55
+ # Since torch script does not support generator expression,
56
+ # have to use concatenation instead of
57
+ # ``tuple(i.to(device) if isinstance(i, Tensor) else i for i in *args)``.
58
+ args = (*args,)
59
+ out_args: Tuple[()] = ()
60
+ for arg in args:
61
+ arg = (arg.to(device),) if isinstance(arg, Tensor) else (arg,)
62
+ out_args = out_args + arg
63
+
64
+ kwargs = {**kwargs}
65
+ for k, v in kwargs.items():
66
+ if isinstance(v, Tensor):
67
+ kwargs[k] = kwargs[k].to(device)
68
+
69
+ if is_device_map_set:
70
+ return module.forward(*out_args, **kwargs)
71
+
72
+ # If the device map is empty, then only CPU tensors are allowed to send over wire,
73
+ # so have to move any GPU tensor to CPU in the output.
74
+ # Since torch script does not support generator expression,
75
+ # have to use concatenation instead of
76
+ # ``tuple(i.cpu() if isinstance(i, Tensor) else i for i in module.forward(*out_args, **kwargs))``.
77
+ ret: Tuple[()] = ()
78
+ for i in module.forward(*out_args, **kwargs):
79
+ i = (i.cpu(),) if isinstance(i, Tensor) else (i,)
80
+ ret = ret + i
81
+ return ret
tmp_j0mzuvp/__pycache__/_remote_module_non_scriptable.cpython-312.pyc ADDED
Binary file (2.61 kB). View file
 
tmp_j0mzuvp/_remote_module_non_scriptable.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import *
2
+
3
+ import torch
4
+ import torch.distributed.rpc as rpc
5
+ from torch import Tensor
6
+ from torch._jit_internal import Future
7
+ from torch.distributed.rpc import RRef
8
+ from typing import Tuple # pyre-ignore: unused import
9
+
10
+
11
+ module_interface_cls = None
12
+
13
+
14
+ def forward_async(self, *args, **kwargs):
15
+ args = (self.module_rref, self.device, self.is_device_map_set, *args)
16
+ kwargs = {**kwargs}
17
+ return rpc.rpc_async(
18
+ self.module_rref.owner(),
19
+ _remote_forward,
20
+ args,
21
+ kwargs,
22
+ )
23
+
24
+
25
+ def forward(self, *args, **kwargs):
26
+ args = (self.module_rref, self.device, self.is_device_map_set, *args)
27
+ kwargs = {**kwargs}
28
+ ret_fut = rpc.rpc_async(
29
+ self.module_rref.owner(),
30
+ _remote_forward,
31
+ args,
32
+ kwargs,
33
+ )
34
+ return ret_fut.wait()
35
+
36
+
37
+ _generated_methods = [
38
+ forward_async,
39
+ forward,
40
+ ]
41
+
42
+
43
+
44
+
45
+ def _remote_forward(
46
+ module_rref: RRef[module_interface_cls], device: str, is_device_map_set: bool, *args, **kwargs):
47
+ module = module_rref.local_value()
48
+ device = torch.device(device)
49
+
50
+ if device.type != "cuda":
51
+ return module.forward(*args, **kwargs)
52
+
53
+ # If the module is on a cuda device,
54
+ # move any CPU tensor in args or kwargs to the same cuda device.
55
+ # Since torch script does not support generator expression,
56
+ # have to use concatenation instead of
57
+ # ``tuple(i.to(device) if isinstance(i, Tensor) else i for i in *args)``.
58
+ args = (*args,)
59
+ out_args: Tuple[()] = ()
60
+ for arg in args:
61
+ arg = (arg.to(device),) if isinstance(arg, Tensor) else (arg,)
62
+ out_args = out_args + arg
63
+
64
+ kwargs = {**kwargs}
65
+ for k, v in kwargs.items():
66
+ if isinstance(v, Tensor):
67
+ kwargs[k] = kwargs[k].to(device)
68
+
69
+ if is_device_map_set:
70
+ return module.forward(*out_args, **kwargs)
71
+
72
+ # If the device map is empty, then only CPU tensors are allowed to send over wire,
73
+ # so have to move any GPU tensor to CPU in the output.
74
+ # Since torch script does not support generator expression,
75
+ # have to use concatenation instead of
76
+ # ``tuple(i.cpu() if isinstance(i, Tensor) else i for i in module.forward(*out_args, **kwargs))``.
77
+ ret: Tuple[()] = ()
78
+ for i in module.forward(*out_args, **kwargs):
79
+ i = (i.cpu(),) if isinstance(i, Tensor) else (i,)
80
+ ret = ret + i
81
+ return ret
tmpd760ylpb/__pycache__/_remote_module_non_scriptable.cpython-312.pyc ADDED
Binary file (2.61 kB). View file
 
tmpd760ylpb/_remote_module_non_scriptable.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import *
2
+
3
+ import torch
4
+ import torch.distributed.rpc as rpc
5
+ from torch import Tensor
6
+ from torch._jit_internal import Future
7
+ from torch.distributed.rpc import RRef
8
+ from typing import Tuple # pyre-ignore: unused import
9
+
10
+
11
+ module_interface_cls = None
12
+
13
+
14
+ def forward_async(self, *args, **kwargs):
15
+ args = (self.module_rref, self.device, self.is_device_map_set, *args)
16
+ kwargs = {**kwargs}
17
+ return rpc.rpc_async(
18
+ self.module_rref.owner(),
19
+ _remote_forward,
20
+ args,
21
+ kwargs,
22
+ )
23
+
24
+
25
+ def forward(self, *args, **kwargs):
26
+ args = (self.module_rref, self.device, self.is_device_map_set, *args)
27
+ kwargs = {**kwargs}
28
+ ret_fut = rpc.rpc_async(
29
+ self.module_rref.owner(),
30
+ _remote_forward,
31
+ args,
32
+ kwargs,
33
+ )
34
+ return ret_fut.wait()
35
+
36
+
37
+ _generated_methods = [
38
+ forward_async,
39
+ forward,
40
+ ]
41
+
42
+
43
+
44
+
45
+ def _remote_forward(
46
+ module_rref: RRef[module_interface_cls], device: str, is_device_map_set: bool, *args, **kwargs):
47
+ module = module_rref.local_value()
48
+ device = torch.device(device)
49
+
50
+ if device.type != "cuda":
51
+ return module.forward(*args, **kwargs)
52
+
53
+ # If the module is on a cuda device,
54
+ # move any CPU tensor in args or kwargs to the same cuda device.
55
+ # Since torch script does not support generator expression,
56
+ # have to use concatenation instead of
57
+ # ``tuple(i.to(device) if isinstance(i, Tensor) else i for i in *args)``.
58
+ args = (*args,)
59
+ out_args: Tuple[()] = ()
60
+ for arg in args:
61
+ arg = (arg.to(device),) if isinstance(arg, Tensor) else (arg,)
62
+ out_args = out_args + arg
63
+
64
+ kwargs = {**kwargs}
65
+ for k, v in kwargs.items():
66
+ if isinstance(v, Tensor):
67
+ kwargs[k] = kwargs[k].to(device)
68
+
69
+ if is_device_map_set:
70
+ return module.forward(*out_args, **kwargs)
71
+
72
+ # If the device map is empty, then only CPU tensors are allowed to send over wire,
73
+ # so have to move any GPU tensor to CPU in the output.
74
+ # Since torch script does not support generator expression,
75
+ # have to use concatenation instead of
76
+ # ``tuple(i.cpu() if isinstance(i, Tensor) else i for i in module.forward(*out_args, **kwargs))``.
77
+ ret: Tuple[()] = ()
78
+ for i in module.forward(*out_args, **kwargs):
79
+ i = (i.cpu(),) if isinstance(i, Tensor) else (i,)
80
+ ret = ret + i
81
+ return ret
tmpdxfzs37c/__pycache__/_remote_module_non_scriptable.cpython-312.pyc ADDED
Binary file (2.61 kB). View file
 
tmpdxfzs37c/_remote_module_non_scriptable.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import *
2
+
3
+ import torch
4
+ import torch.distributed.rpc as rpc
5
+ from torch import Tensor
6
+ from torch._jit_internal import Future
7
+ from torch.distributed.rpc import RRef
8
+ from typing import Tuple # pyre-ignore: unused import
9
+
10
+
11
+ module_interface_cls = None
12
+
13
+
14
+ def forward_async(self, *args, **kwargs):
15
+ args = (self.module_rref, self.device, self.is_device_map_set, *args)
16
+ kwargs = {**kwargs}
17
+ return rpc.rpc_async(
18
+ self.module_rref.owner(),
19
+ _remote_forward,
20
+ args,
21
+ kwargs,
22
+ )
23
+
24
+
25
+ def forward(self, *args, **kwargs):
26
+ args = (self.module_rref, self.device, self.is_device_map_set, *args)
27
+ kwargs = {**kwargs}
28
+ ret_fut = rpc.rpc_async(
29
+ self.module_rref.owner(),
30
+ _remote_forward,
31
+ args,
32
+ kwargs,
33
+ )
34
+ return ret_fut.wait()
35
+
36
+
37
+ _generated_methods = [
38
+ forward_async,
39
+ forward,
40
+ ]
41
+
42
+
43
+
44
+
45
+ def _remote_forward(
46
+ module_rref: RRef[module_interface_cls], device: str, is_device_map_set: bool, *args, **kwargs):
47
+ module = module_rref.local_value()
48
+ device = torch.device(device)
49
+
50
+ if device.type != "cuda":
51
+ return module.forward(*args, **kwargs)
52
+
53
+ # If the module is on a cuda device,
54
+ # move any CPU tensor in args or kwargs to the same cuda device.
55
+ # Since torch script does not support generator expression,
56
+ # have to use concatenation instead of
57
+ # ``tuple(i.to(device) if isinstance(i, Tensor) else i for i in *args)``.
58
+ args = (*args,)
59
+ out_args: Tuple[()] = ()
60
+ for arg in args:
61
+ arg = (arg.to(device),) if isinstance(arg, Tensor) else (arg,)
62
+ out_args = out_args + arg
63
+
64
+ kwargs = {**kwargs}
65
+ for k, v in kwargs.items():
66
+ if isinstance(v, Tensor):
67
+ kwargs[k] = kwargs[k].to(device)
68
+
69
+ if is_device_map_set:
70
+ return module.forward(*out_args, **kwargs)
71
+
72
+ # If the device map is empty, then only CPU tensors are allowed to send over wire,
73
+ # so have to move any GPU tensor to CPU in the output.
74
+ # Since torch script does not support generator expression,
75
+ # have to use concatenation instead of
76
+ # ``tuple(i.cpu() if isinstance(i, Tensor) else i for i in module.forward(*out_args, **kwargs))``.
77
+ ret: Tuple[()] = ()
78
+ for i in module.forward(*out_args, **kwargs):
79
+ i = (i.cpu(),) if isinstance(i, Tensor) else (i,)
80
+ ret = ret + i
81
+ return ret
tmpf5f7c_r3/__pycache__/_remote_module_non_scriptable.cpython-312.pyc ADDED
Binary file (2.61 kB). View file
 
tmpf5f7c_r3/_remote_module_non_scriptable.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import *
2
+
3
+ import torch
4
+ import torch.distributed.rpc as rpc
5
+ from torch import Tensor
6
+ from torch._jit_internal import Future
7
+ from torch.distributed.rpc import RRef
8
+ from typing import Tuple # pyre-ignore: unused import
9
+
10
+
11
+ module_interface_cls = None
12
+
13
+
14
+ def forward_async(self, *args, **kwargs):
15
+ args = (self.module_rref, self.device, self.is_device_map_set, *args)
16
+ kwargs = {**kwargs}
17
+ return rpc.rpc_async(
18
+ self.module_rref.owner(),
19
+ _remote_forward,
20
+ args,
21
+ kwargs,
22
+ )
23
+
24
+
25
+ def forward(self, *args, **kwargs):
26
+ args = (self.module_rref, self.device, self.is_device_map_set, *args)
27
+ kwargs = {**kwargs}
28
+ ret_fut = rpc.rpc_async(
29
+ self.module_rref.owner(),
30
+ _remote_forward,
31
+ args,
32
+ kwargs,
33
+ )
34
+ return ret_fut.wait()
35
+
36
+
37
+ _generated_methods = [
38
+ forward_async,
39
+ forward,
40
+ ]
41
+
42
+
43
+
44
+
45
+ def _remote_forward(
46
+ module_rref: RRef[module_interface_cls], device: str, is_device_map_set: bool, *args, **kwargs):
47
+ module = module_rref.local_value()
48
+ device = torch.device(device)
49
+
50
+ if device.type != "cuda":
51
+ return module.forward(*args, **kwargs)
52
+
53
+ # If the module is on a cuda device,
54
+ # move any CPU tensor in args or kwargs to the same cuda device.
55
+ # Since torch script does not support generator expression,
56
+ # have to use concatenation instead of
57
+ # ``tuple(i.to(device) if isinstance(i, Tensor) else i for i in *args)``.
58
+ args = (*args,)
59
+ out_args: Tuple[()] = ()
60
+ for arg in args:
61
+ arg = (arg.to(device),) if isinstance(arg, Tensor) else (arg,)
62
+ out_args = out_args + arg
63
+
64
+ kwargs = {**kwargs}
65
+ for k, v in kwargs.items():
66
+ if isinstance(v, Tensor):
67
+ kwargs[k] = kwargs[k].to(device)
68
+
69
+ if is_device_map_set:
70
+ return module.forward(*out_args, **kwargs)
71
+
72
+ # If the device map is empty, then only CPU tensors are allowed to send over wire,
73
+ # so have to move any GPU tensor to CPU in the output.
74
+ # Since torch script does not support generator expression,
75
+ # have to use concatenation instead of
76
+ # ``tuple(i.cpu() if isinstance(i, Tensor) else i for i in module.forward(*out_args, **kwargs))``.
77
+ ret: Tuple[()] = ()
78
+ for i in module.forward(*out_args, **kwargs):
79
+ i = (i.cpu(),) if isinstance(i, Tensor) else (i,)
80
+ ret = ret + i
81
+ return ret
tmpiw5dwlcx/__pycache__/_remote_module_non_scriptable.cpython-312.pyc ADDED
Binary file (2.61 kB). View file
 
tmpiw5dwlcx/_remote_module_non_scriptable.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import *
2
+
3
+ import torch
4
+ import torch.distributed.rpc as rpc
5
+ from torch import Tensor
6
+ from torch._jit_internal import Future
7
+ from torch.distributed.rpc import RRef
8
+ from typing import Tuple # pyre-ignore: unused import
9
+
10
+
11
+ module_interface_cls = None
12
+
13
+
14
+ def forward_async(self, *args, **kwargs):
15
+ args = (self.module_rref, self.device, self.is_device_map_set, *args)
16
+ kwargs = {**kwargs}
17
+ return rpc.rpc_async(
18
+ self.module_rref.owner(),
19
+ _remote_forward,
20
+ args,
21
+ kwargs,
22
+ )
23
+
24
+
25
+ def forward(self, *args, **kwargs):
26
+ args = (self.module_rref, self.device, self.is_device_map_set, *args)
27
+ kwargs = {**kwargs}
28
+ ret_fut = rpc.rpc_async(
29
+ self.module_rref.owner(),
30
+ _remote_forward,
31
+ args,
32
+ kwargs,
33
+ )
34
+ return ret_fut.wait()
35
+
36
+
37
+ _generated_methods = [
38
+ forward_async,
39
+ forward,
40
+ ]
41
+
42
+
43
+
44
+
45
+ def _remote_forward(
46
+ module_rref: RRef[module_interface_cls], device: str, is_device_map_set: bool, *args, **kwargs):
47
+ module = module_rref.local_value()
48
+ device = torch.device(device)
49
+
50
+ if device.type != "cuda":
51
+ return module.forward(*args, **kwargs)
52
+
53
+ # If the module is on a cuda device,
54
+ # move any CPU tensor in args or kwargs to the same cuda device.
55
+ # Since torch script does not support generator expression,
56
+ # have to use concatenation instead of
57
+ # ``tuple(i.to(device) if isinstance(i, Tensor) else i for i in *args)``.
58
+ args = (*args,)
59
+ out_args: Tuple[()] = ()
60
+ for arg in args:
61
+ arg = (arg.to(device),) if isinstance(arg, Tensor) else (arg,)
62
+ out_args = out_args + arg
63
+
64
+ kwargs = {**kwargs}
65
+ for k, v in kwargs.items():
66
+ if isinstance(v, Tensor):
67
+ kwargs[k] = kwargs[k].to(device)
68
+
69
+ if is_device_map_set:
70
+ return module.forward(*out_args, **kwargs)
71
+
72
+ # If the device map is empty, then only CPU tensors are allowed to send over wire,
73
+ # so have to move any GPU tensor to CPU in the output.
74
+ # Since torch script does not support generator expression,
75
+ # have to use concatenation instead of
76
+ # ``tuple(i.cpu() if isinstance(i, Tensor) else i for i in module.forward(*out_args, **kwargs))``.
77
+ ret: Tuple[()] = ()
78
+ for i in module.forward(*out_args, **kwargs):
79
+ i = (i.cpu(),) if isinstance(i, Tensor) else (i,)
80
+ ret = ret + i
81
+ return ret
tmpnkix_nz4/__pycache__/_remote_module_non_scriptable.cpython-312.pyc ADDED
Binary file (2.61 kB). View file
 
tmpnkix_nz4/_remote_module_non_scriptable.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import *
2
+
3
+ import torch
4
+ import torch.distributed.rpc as rpc
5
+ from torch import Tensor
6
+ from torch._jit_internal import Future
7
+ from torch.distributed.rpc import RRef
8
+ from typing import Tuple # pyre-ignore: unused import
9
+
10
+
11
+ module_interface_cls = None
12
+
13
+
14
+ def forward_async(self, *args, **kwargs):
15
+ args = (self.module_rref, self.device, self.is_device_map_set, *args)
16
+ kwargs = {**kwargs}
17
+ return rpc.rpc_async(
18
+ self.module_rref.owner(),
19
+ _remote_forward,
20
+ args,
21
+ kwargs,
22
+ )
23
+
24
+
25
+ def forward(self, *args, **kwargs):
26
+ args = (self.module_rref, self.device, self.is_device_map_set, *args)
27
+ kwargs = {**kwargs}
28
+ ret_fut = rpc.rpc_async(
29
+ self.module_rref.owner(),
30
+ _remote_forward,
31
+ args,
32
+ kwargs,
33
+ )
34
+ return ret_fut.wait()
35
+
36
+
37
+ _generated_methods = [
38
+ forward_async,
39
+ forward,
40
+ ]
41
+
42
+
43
+
44
+
45
+ def _remote_forward(
46
+ module_rref: RRef[module_interface_cls], device: str, is_device_map_set: bool, *args, **kwargs):
47
+ module = module_rref.local_value()
48
+ device = torch.device(device)
49
+
50
+ if device.type != "cuda":
51
+ return module.forward(*args, **kwargs)
52
+
53
+ # If the module is on a cuda device,
54
+ # move any CPU tensor in args or kwargs to the same cuda device.
55
+ # Since torch script does not support generator expression,
56
+ # have to use concatenation instead of
57
+ # ``tuple(i.to(device) if isinstance(i, Tensor) else i for i in *args)``.
58
+ args = (*args,)
59
+ out_args: Tuple[()] = ()
60
+ for arg in args:
61
+ arg = (arg.to(device),) if isinstance(arg, Tensor) else (arg,)
62
+ out_args = out_args + arg
63
+
64
+ kwargs = {**kwargs}
65
+ for k, v in kwargs.items():
66
+ if isinstance(v, Tensor):
67
+ kwargs[k] = kwargs[k].to(device)
68
+
69
+ if is_device_map_set:
70
+ return module.forward(*out_args, **kwargs)
71
+
72
+ # If the device map is empty, then only CPU tensors are allowed to send over wire,
73
+ # so have to move any GPU tensor to CPU in the output.
74
+ # Since torch script does not support generator expression,
75
+ # have to use concatenation instead of
76
+ # ``tuple(i.cpu() if isinstance(i, Tensor) else i for i in module.forward(*out_args, **kwargs))``.
77
+ ret: Tuple[()] = ()
78
+ for i in module.forward(*out_args, **kwargs):
79
+ i = (i.cpu(),) if isinstance(i, Tensor) else (i,)
80
+ ret = ret + i
81
+ return ret
tmpp33g8q8r/__pycache__/_remote_module_non_scriptable.cpython-312.pyc ADDED
Binary file (2.61 kB). View file
 
tmpp33g8q8r/_remote_module_non_scriptable.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import *
2
+
3
+ import torch
4
+ import torch.distributed.rpc as rpc
5
+ from torch import Tensor
6
+ from torch._jit_internal import Future
7
+ from torch.distributed.rpc import RRef
8
+ from typing import Tuple # pyre-ignore: unused import
9
+
10
+
11
+ module_interface_cls = None
12
+
13
+
14
+ def forward_async(self, *args, **kwargs):
15
+ args = (self.module_rref, self.device, self.is_device_map_set, *args)
16
+ kwargs = {**kwargs}
17
+ return rpc.rpc_async(
18
+ self.module_rref.owner(),
19
+ _remote_forward,
20
+ args,
21
+ kwargs,
22
+ )
23
+
24
+
25
+ def forward(self, *args, **kwargs):
26
+ args = (self.module_rref, self.device, self.is_device_map_set, *args)
27
+ kwargs = {**kwargs}
28
+ ret_fut = rpc.rpc_async(
29
+ self.module_rref.owner(),
30
+ _remote_forward,
31
+ args,
32
+ kwargs,
33
+ )
34
+ return ret_fut.wait()
35
+
36
+
37
+ _generated_methods = [
38
+ forward_async,
39
+ forward,
40
+ ]
41
+
42
+
43
+
44
+
45
+ def _remote_forward(
46
+ module_rref: RRef[module_interface_cls], device: str, is_device_map_set: bool, *args, **kwargs):
47
+ module = module_rref.local_value()
48
+ device = torch.device(device)
49
+
50
+ if device.type != "cuda":
51
+ return module.forward(*args, **kwargs)
52
+
53
+ # If the module is on a cuda device,
54
+ # move any CPU tensor in args or kwargs to the same cuda device.
55
+ # Since torch script does not support generator expression,
56
+ # have to use concatenation instead of
57
+ # ``tuple(i.to(device) if isinstance(i, Tensor) else i for i in *args)``.
58
+ args = (*args,)
59
+ out_args: Tuple[()] = ()
60
+ for arg in args:
61
+ arg = (arg.to(device),) if isinstance(arg, Tensor) else (arg,)
62
+ out_args = out_args + arg
63
+
64
+ kwargs = {**kwargs}
65
+ for k, v in kwargs.items():
66
+ if isinstance(v, Tensor):
67
+ kwargs[k] = kwargs[k].to(device)
68
+
69
+ if is_device_map_set:
70
+ return module.forward(*out_args, **kwargs)
71
+
72
+ # If the device map is empty, then only CPU tensors are allowed to send over wire,
73
+ # so have to move any GPU tensor to CPU in the output.
74
+ # Since torch script does not support generator expression,
75
+ # have to use concatenation instead of
76
+ # ``tuple(i.cpu() if isinstance(i, Tensor) else i for i in module.forward(*out_args, **kwargs))``.
77
+ ret: Tuple[()] = ()
78
+ for i in module.forward(*out_args, **kwargs):
79
+ i = (i.cpu(),) if isinstance(i, Tensor) else (i,)
80
+ ret = ret + i
81
+ return ret
tmppbcdn8h9/__pycache__/_remote_module_non_scriptable.cpython-312.pyc ADDED
Binary file (2.61 kB). View file
 
tmppbcdn8h9/_remote_module_non_scriptable.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import *
2
+
3
+ import torch
4
+ import torch.distributed.rpc as rpc
5
+ from torch import Tensor
6
+ from torch._jit_internal import Future
7
+ from torch.distributed.rpc import RRef
8
+ from typing import Tuple # pyre-ignore: unused import
9
+
10
+
11
+ module_interface_cls = None
12
+
13
+
14
+ def forward_async(self, *args, **kwargs):
15
+ args = (self.module_rref, self.device, self.is_device_map_set, *args)
16
+ kwargs = {**kwargs}
17
+ return rpc.rpc_async(
18
+ self.module_rref.owner(),
19
+ _remote_forward,
20
+ args,
21
+ kwargs,
22
+ )
23
+
24
+
25
+ def forward(self, *args, **kwargs):
26
+ args = (self.module_rref, self.device, self.is_device_map_set, *args)
27
+ kwargs = {**kwargs}
28
+ ret_fut = rpc.rpc_async(
29
+ self.module_rref.owner(),
30
+ _remote_forward,
31
+ args,
32
+ kwargs,
33
+ )
34
+ return ret_fut.wait()
35
+
36
+
37
+ _generated_methods = [
38
+ forward_async,
39
+ forward,
40
+ ]
41
+
42
+
43
+
44
+
45
+ def _remote_forward(
46
+ module_rref: RRef[module_interface_cls], device: str, is_device_map_set: bool, *args, **kwargs):
47
+ module = module_rref.local_value()
48
+ device = torch.device(device)
49
+
50
+ if device.type != "cuda":
51
+ return module.forward(*args, **kwargs)
52
+
53
+ # If the module is on a cuda device,
54
+ # move any CPU tensor in args or kwargs to the same cuda device.
55
+ # Since torch script does not support generator expression,
56
+ # have to use concatenation instead of
57
+ # ``tuple(i.to(device) if isinstance(i, Tensor) else i for i in *args)``.
58
+ args = (*args,)
59
+ out_args: Tuple[()] = ()
60
+ for arg in args:
61
+ arg = (arg.to(device),) if isinstance(arg, Tensor) else (arg,)
62
+ out_args = out_args + arg
63
+
64
+ kwargs = {**kwargs}
65
+ for k, v in kwargs.items():
66
+ if isinstance(v, Tensor):
67
+ kwargs[k] = kwargs[k].to(device)
68
+
69
+ if is_device_map_set:
70
+ return module.forward(*out_args, **kwargs)
71
+
72
+ # If the device map is empty, then only CPU tensors are allowed to send over wire,
73
+ # so have to move any GPU tensor to CPU in the output.
74
+ # Since torch script does not support generator expression,
75
+ # have to use concatenation instead of
76
+ # ``tuple(i.cpu() if isinstance(i, Tensor) else i for i in module.forward(*out_args, **kwargs))``.
77
+ ret: Tuple[()] = ()
78
+ for i in module.forward(*out_args, **kwargs):
79
+ i = (i.cpu(),) if isinstance(i, Tensor) else (i,)
80
+ ret = ret + i
81
+ return ret
tmpqiqrdevn/__pycache__/_remote_module_non_scriptable.cpython-312.pyc ADDED
Binary file (2.61 kB). View file
 
tmpqiqrdevn/_remote_module_non_scriptable.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import *
2
+
3
+ import torch
4
+ import torch.distributed.rpc as rpc
5
+ from torch import Tensor
6
+ from torch._jit_internal import Future
7
+ from torch.distributed.rpc import RRef
8
+ from typing import Tuple # pyre-ignore: unused import
9
+
10
+
11
+ module_interface_cls = None
12
+
13
+
14
+ def forward_async(self, *args, **kwargs):
15
+ args = (self.module_rref, self.device, self.is_device_map_set, *args)
16
+ kwargs = {**kwargs}
17
+ return rpc.rpc_async(
18
+ self.module_rref.owner(),
19
+ _remote_forward,
20
+ args,
21
+ kwargs,
22
+ )
23
+
24
+
25
+ def forward(self, *args, **kwargs):
26
+ args = (self.module_rref, self.device, self.is_device_map_set, *args)
27
+ kwargs = {**kwargs}
28
+ ret_fut = rpc.rpc_async(
29
+ self.module_rref.owner(),
30
+ _remote_forward,
31
+ args,
32
+ kwargs,
33
+ )
34
+ return ret_fut.wait()
35
+
36
+
37
+ _generated_methods = [
38
+ forward_async,
39
+ forward,
40
+ ]
41
+
42
+
43
+
44
+
45
+ def _remote_forward(
46
+ module_rref: RRef[module_interface_cls], device: str, is_device_map_set: bool, *args, **kwargs):
47
+ module = module_rref.local_value()
48
+ device = torch.device(device)
49
+
50
+ if device.type != "cuda":
51
+ return module.forward(*args, **kwargs)
52
+
53
+ # If the module is on a cuda device,
54
+ # move any CPU tensor in args or kwargs to the same cuda device.
55
+ # Since torch script does not support generator expression,
56
+ # have to use concatenation instead of
57
+ # ``tuple(i.to(device) if isinstance(i, Tensor) else i for i in *args)``.
58
+ args = (*args,)
59
+ out_args: Tuple[()] = ()
60
+ for arg in args:
61
+ arg = (arg.to(device),) if isinstance(arg, Tensor) else (arg,)
62
+ out_args = out_args + arg
63
+
64
+ kwargs = {**kwargs}
65
+ for k, v in kwargs.items():
66
+ if isinstance(v, Tensor):
67
+ kwargs[k] = kwargs[k].to(device)
68
+
69
+ if is_device_map_set:
70
+ return module.forward(*out_args, **kwargs)
71
+
72
+ # If the device map is empty, then only CPU tensors are allowed to send over wire,
73
+ # so have to move any GPU tensor to CPU in the output.
74
+ # Since torch script does not support generator expression,
75
+ # have to use concatenation instead of
76
+ # ``tuple(i.cpu() if isinstance(i, Tensor) else i for i in module.forward(*out_args, **kwargs))``.
77
+ ret: Tuple[()] = ()
78
+ for i in module.forward(*out_args, **kwargs):
79
+ i = (i.cpu(),) if isinstance(i, Tensor) else (i,)
80
+ ret = ret + i
81
+ return ret
tmpqpwscwjm/__pycache__/_remote_module_non_scriptable.cpython-312.pyc ADDED
Binary file (2.61 kB). View file
 
tmpqpwscwjm/_remote_module_non_scriptable.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import *
2
+
3
+ import torch
4
+ import torch.distributed.rpc as rpc
5
+ from torch import Tensor
6
+ from torch._jit_internal import Future
7
+ from torch.distributed.rpc import RRef
8
+ from typing import Tuple # pyre-ignore: unused import
9
+
10
+
11
+ module_interface_cls = None
12
+
13
+
14
+ def forward_async(self, *args, **kwargs):
15
+ args = (self.module_rref, self.device, self.is_device_map_set, *args)
16
+ kwargs = {**kwargs}
17
+ return rpc.rpc_async(
18
+ self.module_rref.owner(),
19
+ _remote_forward,
20
+ args,
21
+ kwargs,
22
+ )
23
+
24
+
25
+ def forward(self, *args, **kwargs):
26
+ args = (self.module_rref, self.device, self.is_device_map_set, *args)
27
+ kwargs = {**kwargs}
28
+ ret_fut = rpc.rpc_async(
29
+ self.module_rref.owner(),
30
+ _remote_forward,
31
+ args,
32
+ kwargs,
33
+ )
34
+ return ret_fut.wait()
35
+
36
+
37
+ _generated_methods = [
38
+ forward_async,
39
+ forward,
40
+ ]
41
+
42
+
43
+
44
+
45
+ def _remote_forward(
46
+ module_rref: RRef[module_interface_cls], device: str, is_device_map_set: bool, *args, **kwargs):
47
+ module = module_rref.local_value()
48
+ device = torch.device(device)
49
+
50
+ if device.type != "cuda":
51
+ return module.forward(*args, **kwargs)
52
+
53
+ # If the module is on a cuda device,
54
+ # move any CPU tensor in args or kwargs to the same cuda device.
55
+ # Since torch script does not support generator expression,
56
+ # have to use concatenation instead of
57
+ # ``tuple(i.to(device) if isinstance(i, Tensor) else i for i in *args)``.
58
+ args = (*args,)
59
+ out_args: Tuple[()] = ()
60
+ for arg in args:
61
+ arg = (arg.to(device),) if isinstance(arg, Tensor) else (arg,)
62
+ out_args = out_args + arg
63
+
64
+ kwargs = {**kwargs}
65
+ for k, v in kwargs.items():
66
+ if isinstance(v, Tensor):
67
+ kwargs[k] = kwargs[k].to(device)
68
+
69
+ if is_device_map_set:
70
+ return module.forward(*out_args, **kwargs)
71
+
72
+ # If the device map is empty, then only CPU tensors are allowed to send over wire,
73
+ # so have to move any GPU tensor to CPU in the output.
74
+ # Since torch script does not support generator expression,
75
+ # have to use concatenation instead of
76
+ # ``tuple(i.cpu() if isinstance(i, Tensor) else i for i in module.forward(*out_args, **kwargs))``.
77
+ ret: Tuple[()] = ()
78
+ for i in module.forward(*out_args, **kwargs):
79
+ i = (i.cpu(),) if isinstance(i, Tensor) else (i,)
80
+ ret = ret + i
81
+ return ret
tmptu2tppnl/__pycache__/_remote_module_non_scriptable.cpython-312.pyc ADDED
Binary file (2.61 kB). View file
 
tmptu2tppnl/_remote_module_non_scriptable.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import *
2
+
3
+ import torch
4
+ import torch.distributed.rpc as rpc
5
+ from torch import Tensor
6
+ from torch._jit_internal import Future
7
+ from torch.distributed.rpc import RRef
8
+ from typing import Tuple # pyre-ignore: unused import
9
+
10
+
11
+ module_interface_cls = None
12
+
13
+
14
+ def forward_async(self, *args, **kwargs):
15
+ args = (self.module_rref, self.device, self.is_device_map_set, *args)
16
+ kwargs = {**kwargs}
17
+ return rpc.rpc_async(
18
+ self.module_rref.owner(),
19
+ _remote_forward,
20
+ args,
21
+ kwargs,
22
+ )
23
+
24
+
25
+ def forward(self, *args, **kwargs):
26
+ args = (self.module_rref, self.device, self.is_device_map_set, *args)
27
+ kwargs = {**kwargs}
28
+ ret_fut = rpc.rpc_async(
29
+ self.module_rref.owner(),
30
+ _remote_forward,
31
+ args,
32
+ kwargs,
33
+ )
34
+ return ret_fut.wait()
35
+
36
+
37
+ _generated_methods = [
38
+ forward_async,
39
+ forward,
40
+ ]
41
+
42
+
43
+
44
+
45
+ def _remote_forward(
46
+ module_rref: RRef[module_interface_cls], device: str, is_device_map_set: bool, *args, **kwargs):
47
+ module = module_rref.local_value()
48
+ device = torch.device(device)
49
+
50
+ if device.type != "cuda":
51
+ return module.forward(*args, **kwargs)
52
+
53
+ # If the module is on a cuda device,
54
+ # move any CPU tensor in args or kwargs to the same cuda device.
55
+ # Since torch script does not support generator expression,
56
+ # have to use concatenation instead of
57
+ # ``tuple(i.to(device) if isinstance(i, Tensor) else i for i in *args)``.
58
+ args = (*args,)
59
+ out_args: Tuple[()] = ()
60
+ for arg in args:
61
+ arg = (arg.to(device),) if isinstance(arg, Tensor) else (arg,)
62
+ out_args = out_args + arg
63
+
64
+ kwargs = {**kwargs}
65
+ for k, v in kwargs.items():
66
+ if isinstance(v, Tensor):
67
+ kwargs[k] = kwargs[k].to(device)
68
+
69
+ if is_device_map_set:
70
+ return module.forward(*out_args, **kwargs)
71
+
72
+ # If the device map is empty, then only CPU tensors are allowed to send over wire,
73
+ # so have to move any GPU tensor to CPU in the output.
74
+ # Since torch script does not support generator expression,
75
+ # have to use concatenation instead of
76
+ # ``tuple(i.cpu() if isinstance(i, Tensor) else i for i in module.forward(*out_args, **kwargs))``.
77
+ ret: Tuple[()] = ()
78
+ for i in module.forward(*out_args, **kwargs):
79
+ i = (i.cpu(),) if isinstance(i, Tensor) else (i,)
80
+ ret = ret + i
81
+ return ret
tmpvkx5qgfg/__pycache__/_remote_module_non_scriptable.cpython-312.pyc ADDED
Binary file (2.61 kB). View file
 
tmpvkx5qgfg/_remote_module_non_scriptable.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import *
2
+
3
+ import torch
4
+ import torch.distributed.rpc as rpc
5
+ from torch import Tensor
6
+ from torch._jit_internal import Future
7
+ from torch.distributed.rpc import RRef
8
+ from typing import Tuple # pyre-ignore: unused import
9
+
10
+
11
+ module_interface_cls = None
12
+
13
+
14
+ def forward_async(self, *args, **kwargs):
15
+ args = (self.module_rref, self.device, self.is_device_map_set, *args)
16
+ kwargs = {**kwargs}
17
+ return rpc.rpc_async(
18
+ self.module_rref.owner(),
19
+ _remote_forward,
20
+ args,
21
+ kwargs,
22
+ )
23
+
24
+
25
+ def forward(self, *args, **kwargs):
26
+ args = (self.module_rref, self.device, self.is_device_map_set, *args)
27
+ kwargs = {**kwargs}
28
+ ret_fut = rpc.rpc_async(
29
+ self.module_rref.owner(),
30
+ _remote_forward,
31
+ args,
32
+ kwargs,
33
+ )
34
+ return ret_fut.wait()
35
+
36
+
37
+ _generated_methods = [
38
+ forward_async,
39
+ forward,
40
+ ]
41
+
42
+
43
+
44
+
45
+ def _remote_forward(
46
+ module_rref: RRef[module_interface_cls], device: str, is_device_map_set: bool, *args, **kwargs):
47
+ module = module_rref.local_value()
48
+ device = torch.device(device)
49
+
50
+ if device.type != "cuda":
51
+ return module.forward(*args, **kwargs)
52
+
53
+ # If the module is on a cuda device,
54
+ # move any CPU tensor in args or kwargs to the same cuda device.
55
+ # Since torch script does not support generator expression,
56
+ # have to use concatenation instead of
57
+ # ``tuple(i.to(device) if isinstance(i, Tensor) else i for i in *args)``.
58
+ args = (*args,)
59
+ out_args: Tuple[()] = ()
60
+ for arg in args:
61
+ arg = (arg.to(device),) if isinstance(arg, Tensor) else (arg,)
62
+ out_args = out_args + arg
63
+
64
+ kwargs = {**kwargs}
65
+ for k, v in kwargs.items():
66
+ if isinstance(v, Tensor):
67
+ kwargs[k] = kwargs[k].to(device)
68
+
69
+ if is_device_map_set:
70
+ return module.forward(*out_args, **kwargs)
71
+
72
+ # If the device map is empty, then only CPU tensors are allowed to send over wire,
73
+ # so have to move any GPU tensor to CPU in the output.
74
+ # Since torch script does not support generator expression,
75
+ # have to use concatenation instead of
76
+ # ``tuple(i.cpu() if isinstance(i, Tensor) else i for i in module.forward(*out_args, **kwargs))``.
77
+ ret: Tuple[()] = ()
78
+ for i in module.forward(*out_args, **kwargs):
79
+ i = (i.cpu(),) if isinstance(i, Tensor) else (i,)
80
+ ret = ret + i
81
+ return ret
tmpxk_w0eue/__pycache__/_remote_module_non_scriptable.cpython-312.pyc ADDED
Binary file (2.61 kB). View file
 
tmpxk_w0eue/_remote_module_non_scriptable.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import *
2
+
3
+ import torch
4
+ import torch.distributed.rpc as rpc
5
+ from torch import Tensor
6
+ from torch._jit_internal import Future
7
+ from torch.distributed.rpc import RRef
8
+ from typing import Tuple # pyre-ignore: unused import
9
+
10
+
11
+ module_interface_cls = None
12
+
13
+
14
+ def forward_async(self, *args, **kwargs):
15
+ args = (self.module_rref, self.device, self.is_device_map_set, *args)
16
+ kwargs = {**kwargs}
17
+ return rpc.rpc_async(
18
+ self.module_rref.owner(),
19
+ _remote_forward,
20
+ args,
21
+ kwargs,
22
+ )
23
+
24
+
25
+ def forward(self, *args, **kwargs):
26
+ args = (self.module_rref, self.device, self.is_device_map_set, *args)
27
+ kwargs = {**kwargs}
28
+ ret_fut = rpc.rpc_async(
29
+ self.module_rref.owner(),
30
+ _remote_forward,
31
+ args,
32
+ kwargs,
33
+ )
34
+ return ret_fut.wait()
35
+
36
+
37
+ _generated_methods = [
38
+ forward_async,
39
+ forward,
40
+ ]
41
+
42
+
43
+
44
+
45
+ def _remote_forward(
46
+ module_rref: RRef[module_interface_cls], device: str, is_device_map_set: bool, *args, **kwargs):
47
+ module = module_rref.local_value()
48
+ device = torch.device(device)
49
+
50
+ if device.type != "cuda":
51
+ return module.forward(*args, **kwargs)
52
+
53
+ # If the module is on a cuda device,
54
+ # move any CPU tensor in args or kwargs to the same cuda device.
55
+ # Since torch script does not support generator expression,
56
+ # have to use concatenation instead of
57
+ # ``tuple(i.to(device) if isinstance(i, Tensor) else i for i in *args)``.
58
+ args = (*args,)
59
+ out_args: Tuple[()] = ()
60
+ for arg in args:
61
+ arg = (arg.to(device),) if isinstance(arg, Tensor) else (arg,)
62
+ out_args = out_args + arg
63
+
64
+ kwargs = {**kwargs}
65
+ for k, v in kwargs.items():
66
+ if isinstance(v, Tensor):
67
+ kwargs[k] = kwargs[k].to(device)
68
+
69
+ if is_device_map_set:
70
+ return module.forward(*out_args, **kwargs)
71
+
72
+ # If the device map is empty, then only CPU tensors are allowed to send over wire,
73
+ # so have to move any GPU tensor to CPU in the output.
74
+ # Since torch script does not support generator expression,
75
+ # have to use concatenation instead of
76
+ # ``tuple(i.cpu() if isinstance(i, Tensor) else i for i in module.forward(*out_args, **kwargs))``.
77
+ ret: Tuple[()] = ()
78
+ for i in module.forward(*out_args, **kwargs):
79
+ i = (i.cpu(),) if isinstance(i, Tensor) else (i,)
80
+ ret = ret + i
81
+ return ret
tokenizer.json ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "version": "1.0",
3
+ "truncation": null,
4
+ "padding": null,
5
+ "added_tokens": [
6
+ {
7
+ "id": 0,
8
+ "content": "<cls>",
9
+ "single_word": false,
10
+ "lstrip": false,
11
+ "rstrip": false,
12
+ "normalized": false,
13
+ "special": true
14
+ },
15
+ {
16
+ "id": 1,
17
+ "content": "<pad>",
18
+ "single_word": false,
19
+ "lstrip": false,
20
+ "rstrip": false,
21
+ "normalized": false,
22
+ "special": true
23
+ },
24
+ {
25
+ "id": 2,
26
+ "content": "<eos>",
27
+ "single_word": false,
28
+ "lstrip": false,
29
+ "rstrip": false,
30
+ "normalized": false,
31
+ "special": true
32
+ },
33
+ {
34
+ "id": 3,
35
+ "content": "<unk>",
36
+ "single_word": false,
37
+ "lstrip": false,
38
+ "rstrip": false,
39
+ "normalized": false,
40
+ "special": true
41
+ },
42
+ {
43
+ "id": 33,
44
+ "content": "<+>",
45
+ "single_word": false,
46
+ "lstrip": false,
47
+ "rstrip": false,
48
+ "normalized": false,
49
+ "special": true
50
+ },
51
+ {
52
+ "id": 34,
53
+ "content": "<->",
54
+ "single_word": false,
55
+ "lstrip": false,
56
+ "rstrip": false,
57
+ "normalized": false,
58
+ "special": true
59
+ },
60
+ {
61
+ "id": 35,
62
+ "content": "<mask>",
63
+ "single_word": false,
64
+ "lstrip": false,
65
+ "rstrip": false,
66
+ "normalized": false,
67
+ "special": true
68
+ },
69
+ {
70
+ "id": 36,
71
+ "content": "<sep>",
72
+ "single_word": false,
73
+ "lstrip": false,
74
+ "rstrip": false,
75
+ "normalized": false,
76
+ "special": true
77
+ }
78
+ ],
79
+ "normalizer": null,
80
+ "pre_tokenizer": null,
81
+ "post_processor": null,
82
+ "decoder": null,
83
+ "model": {
84
+ "type": "BPE",
85
+ "dropout": null,
86
+ "unk_token": "<unk>",
87
+ "continuing_subword_prefix": null,
88
+ "end_of_word_suffix": null,
89
+ "fuse_unk": false,
90
+ "byte_fallback": false,
91
+ "ignore_merges": false,
92
+ "vocab": {
93
+ "<cls>": 0,
94
+ "<pad>": 1,
95
+ "<eos>": 2,
96
+ "<unk>": 3,
97
+ "L": 4,
98
+ "A": 5,
99
+ "G": 6,
100
+ "V": 7,
101
+ "S": 8,
102
+ "E": 9,
103
+ "R": 10,
104
+ "T": 11,
105
+ "I": 12,
106
+ "D": 13,
107
+ "P": 14,
108
+ "K": 15,
109
+ "Q": 16,
110
+ "N": 17,
111
+ "F": 18,
112
+ "Y": 19,
113
+ "M": 20,
114
+ "H": 21,
115
+ "W": 22,
116
+ "C": 23,
117
+ "X": 24,
118
+ "B": 25,
119
+ "U": 26,
120
+ "Z": 27,
121
+ "O": 28,
122
+ "a": 29,
123
+ "t": 30,
124
+ "c": 31,
125
+ "g": 32,
126
+ "<+>": 33,
127
+ "<->": 34,
128
+ "<mask>": 35,
129
+ "<sep>": 36
130
+ },
131
+ "merges": []
132
+ }
133
+ }
tokenizer_config.json ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "0": {
4
+ "content": "<cls>",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": true
10
+ },
11
+ "1": {
12
+ "content": "<pad>",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "2": {
20
+ "content": "<eos>",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "3": {
28
+ "content": "<unk>",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "33": {
36
+ "content": "<+>",
37
+ "lstrip": false,
38
+ "normalized": false,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": true
42
+ },
43
+ "34": {
44
+ "content": "<->",
45
+ "lstrip": false,
46
+ "normalized": false,
47
+ "rstrip": false,
48
+ "single_word": false,
49
+ "special": true
50
+ },
51
+ "35": {
52
+ "content": "<mask>",
53
+ "lstrip": false,
54
+ "normalized": false,
55
+ "rstrip": false,
56
+ "single_word": false,
57
+ "special": true
58
+ },
59
+ "36": {
60
+ "content": "<sep>",
61
+ "lstrip": false,
62
+ "normalized": false,
63
+ "rstrip": false,
64
+ "single_word": false,
65
+ "special": true
66
+ }
67
+ },
68
+ "auto_map": {
69
+ "AutoTokenizer": [
70
+ "glm_tokenizer.gLM2Tokenizer",
71
+ null
72
+ ]
73
+ },
74
+ "clean_up_tokenization_spaces": true,
75
+ "cls_token": "<cls>",
76
+ "eos_token": "<eos>",
77
+ "extra_special_tokens": {},
78
+ "mask_token": "<mask>",
79
+ "model_max_length": 1000000000000000019884624838656,
80
+ "pad_token": "<pad>",
81
+ "sep_token": "<sep>",
82
+ "tokenizer_class": "gLM2Tokenizer",
83
+ "unk_token": "<unk>"
84
+ }