This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import onnx | |
from onnx import helper | |
new_name = "FirefoxMatMulInteger8" | |
def replace_matmul_with_firefoxmatmul(onnx_file_path, output_file_path): | |
# Load the ONNX model | |
model = onnx.load(onnx_file_path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from transformers import GPT2Tokenizer, AutoModelForVision2Seq | |
import requests | |
model_name = "mozilla/distilvit" | |
def load_words_from_url(url): | |
response = requests.get(url) | |
response.raise_for_status() | |
words = {line.strip() for line in response.text.splitlines()} | |
return words |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bert_squeeze.assistants import DistilAssistant | |
from lightning.pytorch import Trainer | |
config_assistant = { | |
"teacher_kwargs": { | |
"pretrained_model": "cnicu/t5-small-booksum", | |
}, | |
"student_kwargs": { | |
"pretrained_model": "cnicu/t5-small-booksum", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import nltk | |
from nltk.corpus import wordnet as wn | |
nltk.download("wordnet") | |
def find_hypernyms(synset_name): | |
synset = wn.synset(synset_name) | |
hypernyms = synset.hypernyms() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Demo of extracting text and links from a rendered web page. | |
$ brew install geckodriver | |
$ python3 -m venv . | |
$ bin/pip install bs4 selenium | |
$ bin/python scrap.py | |
The script looks for an element of a specific id on the page. | |
This can be used to make sure we wait for all JS to execute, and |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# taken from https://stackoverflow.com/a/37211337 | |
def _make_sleep(): | |
async def sleep(delay, result=None, *, loop=None): | |
coro = asyncio.sleep(delay, result=result) | |
task = asyncio.ensure_future(coro, loop=loop) | |
sleep.tasks.add(task) | |
try: | |
return await task | |
except asyncio.CancelledError: | |
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ConcurrentRunner: | |
def __init__(self, max_concurrency=5): | |
self.max_concurrency = 5 | |
self.tasks = [] | |
async def put(self, coro): | |
"""Starts a coroutine if there are 4 or less already running ones. | |
""" | |
# blocks until there's room | |
while len(self.tasks) >= self.max_concurrency: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Like for the IntersectionObserver, we're using here the | |
* Mutation observer to detect when an element attribute is changed | |
* by some Javascript on the page. | |
* | |
* use case: a button is enabled | |
*/ | |
function watchMutation(selector, condition) { | |
var target = document.querySelector(selector); | |
var observer = new MutationObserver(function(mutations) { | |
mutations.forEach(function(mutation) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import functools | |
import logging | |
import graypy | |
import json | |
import time | |
import random | |
from collections import defaultdict, deque | |
from flask import Flask, jsonify, g | |
app = Flask(__name__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# see https://dxr.mozilla.org/mozilla-central/source/testing/marionette/driver.js?from=testing%2Fmarionette%2Fdriver.js#2957 | |
import functools | |
import json | |
from asyncio import open_connection | |
import asyncio | |
from molotov import * | |
class Marionette(object): | |
def __init__(self, host='localhost', port=2828, loop=None): |
NewerOlder