jiangab commited on
Commit
d27f54f
·
verified ·
1 Parent(s): f9ac81c

Upload folder using huggingface_hub

Browse files
Files changed (4) hide show
  1. README.md +86 -86
  2. assets/model_pipe.png +2 -2
  3. assets/rmis_curve.png +2 -2
  4. modules.py +15 -37
README.md CHANGED
@@ -1,86 +1,86 @@
1
- ---
2
- language: en
3
- license: mit
4
- tags:
5
- - pytorch
6
- ---
7
-
8
- <h1 align="center">
9
- FISHER
10
- </h1>
11
-
12
- <div align="center">
13
- <img src="assets/rmis_curve.png" alt="Model Performances on the RMIS Benchmark" style="width:80%; max-width: 1000px">
14
- </div>
15
-
16
-
17
- ## Introduction
18
-
19
- <div align="center">
20
- <img src="assets/model_pipe.png" alt="Model Performances on the RMIS Benchmark" style="width:100%; max-width: 1500px">
21
- </div>
22
-
23
- FISHER is a **F**oundation model for **I**ndustrial **S**ignal compre**HE**nsive **R**epresentation, which models heterogeneous industrial signals (sound, vibration, voltage, etc.) in a unified manner. FISHER accepts arbitrary sampling rates and models the increment of sampling rate as the concatenation of sub-band information, which first splits a STFT spectrogram into sub-bands before processsing it by the ViT encoder. FISHER is trained by teacher student EMA self-distillation.
24
-
25
- To evaluate the model, we develop the RMIS benchmark, which will also be open-sourced in the near future. FISHER achieves the SOTA performances on the RMIS benchmark with much more efficient scaling properties.
26
-
27
- ## Inference
28
-
29
- Please use the following code to infer the signal representation by FISHER.
30
-
31
- ```python
32
- import torch
33
- import torchaudio
34
- import torch.nn.functional as F
35
- from transformers import AutoModel
36
-
37
- model = AutoModel.from_pretrained('jiangab/FISHER-tiny-0723', trust_remote_code=True)
38
- model = model.cuda()
39
- model.eval()
40
-
41
- wav, sr = torchaudio.load('/path/to/local/signal.wav')
42
- # You can replace it with your custom loading function for other signals
43
-
44
- wav = wav - wav.mean()
45
- STFT = torchaudio.transforms.Spectrogram(
46
- n_fft=25 * sr // 1000,
47
- win_length=None,
48
- hop_length=10 * sr // 1000,
49
- power=1,
50
- center=False
51
- )
52
- spec = torch.log(torch.abs(STFT(wav)) + 1e-10)
53
- spec = spec.transpose(-2, -1) # [1, time, freq]
54
- spec = (spec + 3.017344307886898) / (2.1531635155379805 * 2)
55
-
56
- # time-wise cutoff
57
- if spec.shape[-2] > 1024:
58
- spec = spec[:, :1024]
59
- # freq-wise padding
60
- if spec.shape[-1] < model.cfg.band_width:
61
- spec = F.pad(spec, (0, model.cfg.band_width - spec.shape[-1]))
62
- spec = spec.unsqueeze(1).cuda()
63
-
64
- with torch.no_grad():
65
- # Use autocast for mixed precision inference. You can disable it for full precision.
66
- with torch.autocast('cuda'):
67
- repre = model.extract_features(spec)
68
- print(repre.shape)
69
- ```
70
-
71
- ## Acknowledgements
72
-
73
- FISHER is developed based on [EAT](https://github.com/cwx-worst-one/EAT) and [fairseq](https://github.com/facebookresearch/fairseq). We thank these authors for open-sourcing their works.
74
-
75
- ## Citation
76
-
77
- If you find FISHER useful, please cite the following paper.
78
-
79
- ```bibtex
80
- @article{fan2025fisher,
81
- title={FISHER: A Foundation Model for Multi-Modal Industrial Signal Comprehensive Representation},
82
- author={Fan, Pingyi and Jiang, Anbai and Zhang, Shuwei and Lv, Zhiqiang and Han, Bing and Zheng, Xinhu and Liang, Wenrui and Li, Junjie and Zhang, Wei-Qiang and Qian, Yanmin and Chen, Xie and Lu, Cheng and Liu, Jia},
83
- journal={arXiv preprint arXiv:2507.16696},
84
- year={2025}
85
- }
86
- ```
 
1
+ ---
2
+ language: en
3
+ license: mit
4
+ tags:
5
+ - pytorch
6
+ ---
7
+
8
+ <h1 align="center">
9
+ FISHER
10
+ </h1>
11
+
12
+ <div align="center">
13
+ <img src="assets/rmis_curve.png" alt="Model Performances on the RMIS Benchmark" style="width:85%; max-width: 2000px">
14
+ </div>
15
+
16
+
17
+ ## Introduction
18
+
19
+ <div align="center">
20
+ <img src="assets/model_pipe.png" alt="Model Performances on the RMIS Benchmark" style="width:90%; max-width: 1500px">
21
+ </div>
22
+
23
+ FISHER is a **F**oundation model for **I**ndustrial **S**ignal compre**HE**nsive **R**epresentation, which models heterogeneous industrial signals (sound, vibration, voltage, etc.) in a unified manner. FISHER accepts arbitrary sampling rates and models the increment of sampling rate as the concatenation of sub-band information, which first splits a STFT spectrogram into sub-bands before processsing it by the ViT encoder. FISHER is trained by teacher student EMA self-distillation.
24
+
25
+ To evaluate the model, we develop the RMIS benchmark, which will also be open-sourced in the near future. FISHER achieves the SOTA performances on the RMIS benchmark with much more efficient scaling properties.
26
+
27
+ ## Inference
28
+
29
+ Please use the following code to infer the signal representation by FISHER.
30
+
31
+ ```python
32
+ import torch
33
+ import torchaudio
34
+ import torch.nn.functional as F
35
+ from transformers import AutoModel
36
+
37
+ model = AutoModel.from_pretrained('jiangab/FISHER-tiny-0723', trust_remote_code=True)
38
+ model = model.cuda()
39
+ model.eval()
40
+
41
+ wav, sr = torchaudio.load('/path/to/local/signal.wav')
42
+ # You can replace it with your custom loading function for other signals
43
+
44
+ wav = wav - wav.mean()
45
+ STFT = torchaudio.transforms.Spectrogram(
46
+ n_fft=25 * sr // 1000,
47
+ win_length=None,
48
+ hop_length=10 * sr // 1000,
49
+ power=1,
50
+ center=False
51
+ )
52
+ spec = torch.log(torch.abs(STFT(wav)) + 1e-10)
53
+ spec = spec.transpose(-2, -1) # [1, time, freq]
54
+ spec = (spec + 3.017344307886898) / (2.1531635155379805 * 2)
55
+
56
+ # time-wise cutoff
57
+ if spec.shape[-2] > 1024:
58
+ spec = spec[:, :1024]
59
+ # freq-wise padding
60
+ if spec.shape[-1] < model.cfg.band_width:
61
+ spec = F.pad(spec, (0, model.cfg.band_width - spec.shape[-1]))
62
+ spec = spec.unsqueeze(1).cuda()
63
+
64
+ with torch.no_grad():
65
+ # Use autocast for mixed precision inference. You can disable it for full precision.
66
+ with torch.autocast('cuda'):
67
+ repre = model.extract_features(spec)
68
+ print(repre.shape)
69
+ ```
70
+
71
+ ## Acknowledgements
72
+
73
+ FISHER is developed based on [EAT](https://github.com/cwx-worst-one/EAT) and [fairseq](https://github.com/facebookresearch/fairseq). We thank these authors for open-sourcing their works.
74
+
75
+ ## Citation
76
+
77
+ If you find FISHER useful, please cite the following paper.
78
+
79
+ ```bibtex
80
+ @article{fan2025fisher,
81
+ title={FISHER: A Foundation Model for Multi-Modal Industrial Signal Comprehensive Representation},
82
+ author={Fan, Pingyi and Jiang, Anbai and Zhang, Shuwei and Lv, Zhiqiang and Han, Bing and Zheng, Xinhu and Liang, Wenrui and Li, Junjie and Zhang, Wei-Qiang and Qian, Yanmin and Chen, Xie and Lu, Cheng and Liu, Jia},
83
+ journal={arXiv preprint arXiv:2507.16696},
84
+ year={2025}
85
+ }
86
+ ```
assets/model_pipe.png CHANGED

Git LFS Details

  • SHA256: a1c3a1f1f762135e62b6d97826553a3baa435308e20f3c58940eb1c164f9e355
  • Pointer size: 132 Bytes
  • Size of remote file: 3.43 MB

Git LFS Details

  • SHA256: 3deecee0d725ca612412e9a708ea720cf013db904d81b3c9b231a4a6fb9b77e7
  • Pointer size: 131 Bytes
  • Size of remote file: 519 kB
assets/rmis_curve.png CHANGED

Git LFS Details

  • SHA256: 21e78c74d71589376606b149ac27e1a7b2b262197abd6fa20ebcb8555fffb765
  • Pointer size: 131 Bytes
  • Size of remote file: 403 kB

Git LFS Details

  • SHA256: d4881ff2b97dd295d9b0bfbd3ff126f80e7e946e6306af78c370b2e6f85a5081
  • Pointer size: 131 Bytes
  • Size of remote file: 414 kB
modules.py CHANGED
@@ -215,19 +215,13 @@ class AltAttention(nn.Module):
215
  self.num_heads = num_heads
216
  head_dim = dim // num_heads
217
  self.scale = qk_scale or head_dim ** -0.5
 
218
 
219
  self.qkv = nn.Linear(dim, dim * 3, bias=qkv_bias)
220
  self.attn_drop = nn.Dropout(attn_drop)
221
  self.proj = nn.Linear(dim, dim)
222
  self.proj_drop = nn.Dropout(proj_drop)
223
 
224
- self.cosine_attention = cosine_attention
225
-
226
- if cosine_attention:
227
- self.logit_scale = nn.Parameter(
228
- torch.log(10 * torch.ones((num_heads, 1, 1))), requires_grad=True
229
- )
230
-
231
  def forward(self, x, padding_mask=None, alibi_bias=None):
232
  B, N, C = x.shape
233
  qkv = (
@@ -235,39 +229,23 @@ class AltAttention(nn.Module):
235
  .reshape(B, N, 3, self.num_heads, C // self.num_heads)
236
  .permute(2, 0, 3, 1, 4) # qkv x B x H x L x D
237
  )
238
- q, k, v = (
239
- qkv[0],
240
- qkv[1],
241
- qkv[2],
242
- ) # make torchscript happy (cannot use tensor as tuple)
243
-
244
- dtype = q.dtype
245
-
246
- if self.cosine_attention:
247
- # cosine attention
248
- attn = F.normalize(q, dim=-1) @ F.normalize(k, dim=-1).transpose(-2, -1)
249
- logit_scale = torch.clamp(
250
- self.logit_scale, max=torch.log(torch.tensor(1.0 / 0.01))
251
- ).exp()
252
- attn = attn * logit_scale
253
  else:
254
- q = q * self.scale
255
- attn = q @ k.transpose(-2, -1)
256
 
257
- if alibi_bias is not None:
258
- attn = attn.type_as(alibi_bias)
259
- attn[:, : alibi_bias.size(1)] += alibi_bias
 
 
 
 
260
 
261
- if padding_mask is not None and padding_mask.any():
262
- attn = attn.masked_fill(
263
- padding_mask.unsqueeze(1).unsqueeze(2).to(torch.bool),
264
- float("-inf"),
265
- )
266
-
267
- attn = attn.softmax(dim=-1, dtype=torch.float32).to(dtype=dtype)
268
- attn = self.attn_drop(attn)
269
- x = (attn @ v).transpose(1, 2) #
270
- x = x.reshape(B, N, C)
271
  x = self.proj(x)
272
  x = self.proj_drop(x)
273
  return x
 
215
  self.num_heads = num_heads
216
  head_dim = dim // num_heads
217
  self.scale = qk_scale or head_dim ** -0.5
218
+ assert cosine_attention is False
219
 
220
  self.qkv = nn.Linear(dim, dim * 3, bias=qkv_bias)
221
  self.attn_drop = nn.Dropout(attn_drop)
222
  self.proj = nn.Linear(dim, dim)
223
  self.proj_drop = nn.Dropout(proj_drop)
224
 
 
 
 
 
 
 
 
225
  def forward(self, x, padding_mask=None, alibi_bias=None):
226
  B, N, C = x.shape
227
  qkv = (
 
229
  .reshape(B, N, 3, self.num_heads, C // self.num_heads)
230
  .permute(2, 0, 3, 1, 4) # qkv x B x H x L x D
231
  )
232
+ q, k, v = qkv[0], qkv[1], qkv[2] # (B, H, N, D)
233
+
234
+ # key padding mask: True for preserve, False for padding
235
+ if padding_mask is not None and padding_mask.any():
236
+ key_padding_mask = ~padding_mask # (B, N)
 
 
 
 
 
 
 
 
 
 
237
  else:
238
+ key_padding_mask = None
 
239
 
240
+ # use pytorch SDPA, auto select Flash Attention
241
+ x = F.scaled_dot_product_attention(
242
+ q, k, v,
243
+ attn_mask=key_padding_mask,
244
+ dropout_p=self.attn_drop.p if self.training else 0.0,
245
+ scale=self.scale,
246
+ ) # (B, H, N, D)
247
 
248
+ x = x.transpose(1, 2).reshape(B, N, C)
 
 
 
 
 
 
 
 
 
249
  x = self.proj(x)
250
  x = self.proj_drop(x)
251
  return x