-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy path__init__.py
More file actions
171 lines (159 loc) · 3.58 KB
/
__init__.py
File metadata and controls
171 lines (159 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import contextlib
with contextlib.suppress(ImportError):
from ._preload import preload
preload()
import infinicore.context as context
import infinicore.nn as nn
# Import context functions
from infinicore.context import (
get_device,
get_device_count,
get_stream,
is_graph_recording,
set_device,
start_graph_recording,
stop_graph_recording,
sync_device,
sync_stream,
)
from infinicore.device import device
from infinicore.device_event import DeviceEvent
from infinicore.dtype import (
bfloat16,
bool,
cdouble,
cfloat,
chalf,
complex32,
complex64,
complex128,
double,
dtype,
float,
float16,
float32,
float64,
half,
int,
int8,
int16,
int32,
int64,
long,
short,
uint8,
)
from infinicore.ops.add import add
from infinicore.ops.add_rms_norm import add_rms_norm
from infinicore.ops.attention import attention
from infinicore.ops.kv_caching import kv_caching
from infinicore.ops.matmul import matmul
from infinicore.ops.mha_kvcache import mha_kvcache
from infinicore.ops.mha_varlen import mha_varlen
from infinicore.ops.mul import mul
from infinicore.ops.narrow import narrow
from infinicore.ops.paged_attention import paged_attention
from infinicore.ops.paged_attention_prefill import paged_attention_prefill
from infinicore.ops.paged_caching import paged_caching
from infinicore.ops.rearrange import rearrange
from infinicore.ops.squeeze import squeeze
from infinicore.ops.unsqueeze import unsqueeze
from infinicore.tensor import (
Tensor,
empty,
empty_like,
from_blob,
from_list,
from_numpy,
from_torch,
ones,
strided_empty,
strided_from_blob,
zeros,
)
# Re-attempt flash_attn preload after _infinicore.so (and its DTK/HIP
# dependencies) are loaded. The initial preload() above may have failed
# because flash_attn_2_cuda.so's dependencies were not yet available.
# Now that _infinicore.so is loaded we can call dlopen(path, RTLD_GLOBAL)
# to upgrade the already-loaded library from RTLD_LOCAL to RTLD_GLOBAL,
# making its symbols visible to dlsym(RTLD_DEFAULT).
with contextlib.suppress(Exception):
from ._preload import preload_flash_attn
preload_flash_attn()
__all__ = [
# Modules.
"context",
"nn",
# Classes.
"device",
"DeviceEvent",
"dtype",
"Tensor",
# Context functions.
"get_device",
"get_device_count",
"get_stream",
"set_device",
"sync_device",
"sync_stream",
"is_graph_recording",
"start_graph_recording",
"stop_graph_recording",
# Data Types.
"bfloat16",
"bool",
"cdouble",
"cfloat",
"chalf",
"complex32",
"complex64",
"complex128",
"double",
"float",
"float16",
"float32",
"float64",
"half",
"int",
"int8",
"int16",
"int32",
"int64",
"long",
"short",
"uint8",
# Operators.
"add",
"add_rms_norm",
"add_rms_norm_",
"attention",
"kv_caching",
"matmul",
"mul",
"narrow",
"squeeze",
"unsqueeze",
"rearrange",
"empty",
"empty_like",
"from_blob",
"from_list",
"from_numpy",
"from_torch",
"mha_kvcache",
"mha_varlen",
"paged_caching",
"paged_attention",
"paged_attention_prefill",
"ones",
"strided_empty",
"strided_from_blob",
"zeros",
]
use_ntops = False
with contextlib.suppress(ImportError, ModuleNotFoundError):
import sys
import ntops
for op_name in ntops.torch.__all__:
getattr(ntops.torch, op_name).__globals__["torch"] = sys.modules[__name__]
use_ntops = True