Skip to content

Instantly share code, notes, and snippets.

@wangkuiyi
wangkuiyi / iree-build-ios-stdout-stderr.txt
Last active January 5, 2023 17:53
CMake configuration errors from IREE
-- The ASM compiler identification is Clang with GNU-like command-line
-- Found assembler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- The C compiler identification is AppleClang 14.0.0.14000029
-- The CXX compiler identification is AppleClang 14.0.0.14000029
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
@wangkuiyi
wangkuiyi / t.py
Created October 24, 2022 16:35
Train a two-tower model using the MovieLens 100K dataset
import torch
import pandas
class TT(torch.nn.Module):
def __init__(self, n_user, n_item):
super(TT, self).__init__()
# The dimensionality of embedding vectors 32 is from
#https://towardsdatascience.com/movielens-1m-deep-dive-part-ii-tensorflow-recommenders-4ca358cc886e
emb_dim = 128
self.u = torch.nn.Embedding(n_user, emb_dim)
@wangkuiyi
wangkuiyi / plot_u.data.py
Last active October 24, 2022 02:16
The marginal and joint distribution of MovieLens-100K data
import pandas
import seaborn as sns
import matplotlib.pyplot as plt
from typing import Dict, List, Tuple
def freq(df: pandas.DataFrame, column_name: str) -> Dict[int, int]:
"""Count the word frequency of a pandas data frame column."""
ret = {}
for i in range(len(df[column_name])):
k = df[column_name][i]
@wangkuiyi
wangkuiyi / gist:276098ff405b5b475ab3deac870c8897
Created June 7, 2022 06:09
Debug PyTorch programs Using gdb python
(base) wkyi@u22vm:~$ gdb python
GNU gdb (Ubuntu 12.0.90-0ubuntu1) 12.0.90
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from python...
(gdb) b at::Tensor::mm
Function "at::Tensor::mm" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (at::Tensor::mm) pending.
;; SICP p.46 Exercise 1.16

#lang racket

;; The recursive procedure of power.  Both the
;; space and computation cost are O(n).
(define (power-rec b n)
  (if (= n 0)
      1
@wangkuiyi
wangkuiyi / s.py
Created May 4, 2021 04:18
The simplest distributed PyTorch example
# To run this program, type the following commands in a terminal.
#
# MASTER_ADDR=localhost MASTER_PORT=12306 RANK=0 WORLD_SIZE=2 python3 s.py &
# MASTER_ADDR=localhost MASTER_PORT=12306 RANK=1 WORLD_SIZE=2 python3 s.py &
import os
import sys
import time
import logging
@wangkuiyi
wangkuiyi / assoc_emb.py
Created April 25, 2021 01:55
torch.nn.AssocEmb
import torch
class AssocEmb(torch.nn.Module):
def __init__(self, dim: list[int]):
super(AssocEmb, self).__init__()
self.dim = dim
self.tbl = torch.nn.ParameterDict()
def forward(self, idx: str) -> torch.Tensor:
@wangkuiyi
wangkuiyi / init.el
Created April 18, 2021 00:38
Move Emacs window to the right half of the screen
;; Move emacs window to the right half screen. -50 is a hack for macOS.
(let ((frame (selected-frame))
(one-half-display-pixel-width (/ (display-pixel-width) 2)))
(set-frame-width frame one-half-display-pixel-width nil 'pixelwise)
(set-frame-height frame (- (display-pixel-height) 50) nil 'pixelwise)
(set-frame-position frame one-half-display-pixel-width 0))
@wangkuiyi
wangkuiyi / interleave_async_generators.py
Created April 2, 2021 01:36
Read asynchronously from multiple async generators
import asyncio
from aiostream import stream # You need to pip install aiostream
from datetime import datetime
async def agint(n:int, v:int):
for _ in range(n):
await asyncio.sleep(0.1)
yield v

Ant Financial Individual Contributor License Agreement

Thank you for your interest in contributing documentation and related software code to a project hosted or managed by Ant Financial Services Group, or any of its affiliates. In order to clarify the intellectual property license granted with Contributions from any person or entity, Ant Financial must have a Contributor License Agreement ("CLA") on file that has been signed by each Contributor, indicating agreement to the license terms below. This version of the Contributor License Agreement allows an individual to submit Contributions to the applicable project. If you are making a submission on behalf of a legal entity, then you should sign the separation Corporate Contributor License Agreement.

You accept and agree to the following terms and conditions for Your present and future Contributions submitted to Ant Financial. Except for the license granted herein to Ant Financial and recipients of documentation and software distributed by Ant Financial, Yo