This file contains hidden or 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 torch as t | |
from torch.autograd import grad | |
from scipy.sparse.linalg import LinearOperator, eigsh | |
import numpy as np | |
def get_hessian_eigenvectors(model, loss_fn, train_data_loader, num_batches, device, n_top_vectors, param_extract_fn): | |
""" | |
model: a pytorch model | |
loss_fn: a pytorch loss function | |
train_data_loader: a pytorch data loader |
This file contains hidden or 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 React, { useState, useEffect } from 'react'; | |
import { GenericInput } from './TextEdit'; | |
const App = () => { | |
type myObj = { | |
name: string; | |
numLettersInName: number; | |
} |
This file contains hidden or 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 React from 'react'; | |
export function GenericInput<T>(props: { value: T, dataToString: (value: T) => string, dataFromString: (input: string) => T, onChange: (value: T) => void }) { | |
const isNumberField = typeof (props.value) === "number"; | |
return (<input | |
value={props.dataToString(props.value)} | |
onChange={e => props.onChange(props.dataFromString(e.target.value))} | |
type={isNumberField ? "number" : "text"} | |
/>); | |
} |