Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dill.source.getsource applied on lambda function returns many cached lines #624

Open
dcasbol opened this issue Oct 18, 2023 · 0 comments
Open

Comments

@dcasbol
Copy link

dcasbol commented Oct 18, 2023

Might be related to issue 583, but I'm not sure.
This is how I replicate it on a Python 3.11.4 terminal and dill 0.3.6

class Demo:
    def __init__(self, a):
            print(getsource(self.a))

d = Demo(a=lambda x: 2*x+1)

Running this code should print a series of code lines that look like taken from some package cache. Mine looked like this:

import multiprocessing
multiprocessing.cpu_count()
import os
os.path.basename("/path/dir/hola.txt")
[ 100 * (2**i) for i in range(10) ]
import subprocess
p = subprocess.run(["ls"], capture_output=True)
p
p.stdout
p.stdout.split("\n")
p.stdout.split(b"\n")
p.stdout.strip("\n")
p.stdout.strip(b"\n")
p.stdout.strip(b"\n").strip()
p.stdout.strip(b"\n").strip().split(b"\n")
p.stdout.strip(b"\n").strip().split(b"\n")[-1]
import matplotlib.pyplot as plt
import numpy as np
x = np.rand([3,3])
x = np.random.rand([3,3])
x = np.zeros([3,3])
x[1,2] = 2
plt.figure()
plt.imshow(x)
plt.colorbar()
plt.show()
import matplotlib.pyplot as plt
import numpy as np
x = np.zeros([3,3])
x[1,2] = 1
plt.imshow(x, clim=(0,1))
plt.colorbar(cmap='seismic')
plt.imshow(x, clim=(0,1), cmap='seismic')
plt.show()
import gym
env = gym.make('CartPole-v0')
from glob import glob
glob("*.jl")
from glob import glob
for file in glob("*/*.jl"):
	print(file)
for file in glob("**/*.jl"):
	print(file)
for file in glob("*.jl"):
	print(file)
from badger_utils.sacred import SacredUtils
from blacksquare import Crossword, black, empty, across, down
from blacksquare import Crossword, across, down, black, empty
import collections
collections.Mapping
from blacksquare import Crossword, across, down, black, empty
xw = Crossword(5)
xw.pprint(numbers=True)
xw.to_pdf('test.pdf')
solutions = xw.find_area_solutions((across, 1))
solutions[0]
len(solutions)
solutions[1]
xw.get_indices()
xw.get_indices(0)
solution[0].get_indices(0]
solution[0].get_indices(0)
solutions[0].get_indices(0)
from blacksquare import Crossword, across, down, black, empty
xw = Crossword(5)
from random import randint
for i in range(3):
	x,y = randint(0,4), randint(0,4)
	xw[(x,y)] = black
xw
solutions = xw.find_area_solutions((across,1))
solutions[0]
solutions[0].to_pdf("test.pdf")
solutions[1]
dir(solutions[1])
solutions[1].to_puz("test.txt")
solutions[1].clues
import torch.nn as  nn
p = nn.Parameter([1,2,3])
p = nn.Parameter(torch.zeros(5))
import torch
p = nn.Parameter(torch.zeros(5))
p
torch.randn(5)
import torch
torch.zeros(1,3)
_.size()
import torch
a = torch.randn(3,4,5)
a.size()
b = torch.randn(5,1)
c = torch.matmul(a,b)
c.size()
DIM_SIZE = 128
import torch
import torch.nn as nn
DIM_SIZE = 128
class ANeuron(nn.Module):
    def __init__(self, num_connections=5):
        super().__init__()
        self.queries = [ nn.Parameter(torch.randn(DIM_SIZE, 1)) for _ in range(num_connections) ]
        self.trans = nn.Sequential(
            nn.Linear(DIM_SIZE*num_connections, DIM_SIZE//2),
            nn.ReLU(),
            nn.Linear(DIM_SIZE//2, DIM_SIZE)
        )
    def forward(self, x):
        # x: [B,N,D]
        att_list = list()
        for q in self.queries:
            a = torch.matmul(x, self.query).softmax(1) # [B,N,1]
            attended = (x * a).sum(1)
            att_list.append(attended)
        neuron_x = torch.cat(att_list, dim=1)
        return self.trans(neuron_x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant