Skip to content

Instantly share code, notes, and snippets.

View MahmoudAshraf97's full-sized avatar
🏠
Working from home

Mahmoud Ashraf MahmoudAshraf97

🏠
Working from home
View GitHub Profile
@MahmoudAshraf97
MahmoudAshraf97 / repro.py
Created November 25, 2025 18:20
TRT Reproduce
import numpy as np
import torch
import tensorrt as trt
from polygraphy.backend.trt import CreateConfig, Profile
def build_encoder_t_gather_engine(encoder_output_shape):
"""
Build a TensorRT engine that:
input_0: encoder_output, shape (B, T, H), dtype float32
@MahmoudAshraf97
MahmoudAshraf97 / silero_v5_batched.py
Created February 19, 2025 12:36
Silero V5 for batched inference
from typing import Tuple
import line_profiler
import torch
import torch.nn as nn
class Encoder(nn.Module):
def __init__(self, feature_size, filter_length, hop_length):
super(Encoder, self).__init__()
@MahmoudAshraf97
MahmoudAshraf97 / benchmark_fe.py
Last active October 31, 2024 22:25
Benchmarking several feature extraction methods
import os
import timeit
print(f"Cores: {os.sched_getaffinity(0)}")
import cupy as cp
import numpy as np
import torch
def stft(
@MahmoudAshraf97
MahmoudAshraf97 / silero_v4.py
Last active August 15, 2024 13:40
Reference Implementation of Silero V4 VAD model
import torch
import torch.nn as nn
import torch.nn.functional as F
class STFT(nn.Module):
def __init__(self, filter_length, hop_length):
super(STFT, self).__init__()
self.filter_length = filter_length
self.hop_length = hop_length
@MahmoudAshraf97
MahmoudAshraf97 / silero_v5.py
Last active October 21, 2025 18:17
Reference Implementation of Silero V5 and V6 VAD model
import torch
import torch.nn as nn
import torch.nn.functional as F
class STFT(nn.Module):
def __init__(self, filter_length, hop_length):
super(STFT, self).__init__()
self.filter_length = filter_length
self.hop_length = hop_length
@MahmoudAshraf97
MahmoudAshraf97 / torch_to_hf.py
Created May 6, 2024 17:32
Conversion script for MMS-300 Alignment model
import os
import torch
from torchaudio.models import wav2vec2_model
from transformers import Wav2Vec2ForCTC, Wav2Vec2CTCTokenizer, AutoConfig
import json
import argparse
import tempfile
# Initialize parser
parser = argparse.ArgumentParser()
import torch
from detectron2.config import get_cfg
from detectron2 import model_zoo
from detectron2.engine import DefaultPredictor
import numpy as np
import cv2
from datetime import datetime
import skvideo.io
import json