Skip to content

Instantly share code, notes, and snippets.

@malfet
malfet / gh_transfer_issues.py
Created February 1, 2023 01:04
Transfer issues from pytorch/torchdynamo to pytorch/pytorch
#!/usr/bin/env python3
from collections import namedtuple
from typing import Tuple, List
GH_GET_REPO_ID = """
query ($owner: String = "pytorch", $name: String = "pytorch") {
repository(name: $name, owner: $owner) {
id
@malfet
malfet / add_issues_to_mps_project.py
Created October 12, 2022 05:41
Project management automation for MPS
#!/usr/bin/env python3
MPS_PROJECT_NUMBER = 26
GH_GET_PROJECT_ID = """
query ($owner: String = "pytorch", $name: String = "pytorch", $number: Int = 26) {
repository(name: $name, owner: $owner) {
projectV2(number: $number) {
id
}
# Very restricted unpickler
# Based of https://github.com/python/cpython/blob/main/Lib/pickle.py
# Expected to be useful for loading PyTorch model weights
# For example:
# data = urllib.request.urlopen('https://download.pytorch.org/models/resnet50-0676ba61.pth').read()
# buf = io.BytesIO(data)
# weights = torch.load(buf, pickle_module=WeightsUnpickler)
import sys
from sys import maxsize
#!/usr/bin/env python3
GH_GET_VIEWER_LOGIN = """
query {
viewer {
login
}
}
"""
@malfet
malfet / query_metal_devices.mm
Last active June 8, 2022 17:35
ObjC script to query available metal devices
// Compile me as
// clang++ query_metal_devices.mm -framework Metal -framework Foundation
#include <Metal/Metal.h>
int main() {
@autoreleasepool {
NSArray* devices = [MTLCopyAllDevices() autorelease];
NSLog(@"Metal device count %lu", devices.count);
for (unsigned long i = 0 ; i < devices.count ; i++) {
id<MTLDevice> device = devices[i];
@malfet
malfet / get_comits.py
Last active June 8, 2022 00:11
Trying to fetch all commit PRs using GraphQL API
#!/usr/bin/env python3
# Trying to use graphQL to fetch all commits associated with PR https://github.com/pytorch/pytorch/pull/77471
# Expect to get 700+ commits for for some reason pagination ends after first 250
# Needs valid PAT passed via GITHUB_TOKEN environment variable
GH_GET_COMMITS = """
query($cursor: String) {
repository(owner: "pytorch", name: "pytorch") {
pullRequest(number: 77471) {
commits(first: 100, after: $cursor) {
@malfet
malfet / get_mac_annotations.js
Last active March 22, 2022 21:05
GQL to query annotations
{
repository(name: "pytorch", owner: "pytorch") {
object(oid: "7dd08230117f4fa8bb82b3524e90fb00340198c7") {
... on Commit {
checkSuites(first: 100, filterBy: {appId: 15368}) {
nodes {
workflowRun {
workflow {
name
}
@malfet
malfet / gist:9b93bc7eeddeaf1d84546efc4f0c577f
Last active March 25, 2022 01:17
GraphQL query causing HTTP/502
query {
repository(owner: "pytorch", name: "pytorch") {
pullRequest(number: 68111) {
closed
isCrossRepository
author {
login
}
title
body
@malfet
malfet / gh_association_curiosities.py
Created January 26, 2022 17:07
Querying author association from github
#!/usr/bin/env python3
# Author of https://github.com/pytorch/pytorch/pull/71735 is me (malfet)
# And if executed with my PAT it will return my association as "MEMBER"
# But if executed by somebody outside of org, it will say that association is "CONTRIBUTOR"
# Instead of getting PAT, one can simply execute the query at https://docs.github.com/en/graphql/overview/explorer
GH_GET_ASSOCIATION = """
query {
repository(owner: "pytorch", name: "pytorch") {
pullRequest(number: 71735) {
@malfet
malfet / get_default_branch.py
Created January 19, 2022 17:32
Print default branches for public repos in pytorch org
#!/usr/bin/env python3
# Print default branch for public repos in pytorch org
# Requires github token
from typing import Any, Dict
GH_SEARCH_REPO_REQ = """
query($cursor: String) {
search(type: REPOSITORY, query: "org:pytorch", first: 100, after: $cursor) {
nodes {
... on Repository {