spikingjelly.activation_based.ann2snn.examples package#

CNN for MNIST#

spikingjelly.activation_based.ann2snn.examples.cnn_mnist.parse_args()[源代码]#
spikingjelly.activation_based.ann2snn.examples.cnn_mnist.val(net, device, data_loader, T=None)[源代码]#
spikingjelly.activation_based.ann2snn.examples.cnn_mnist.save_results(results, output_path)[源代码]#
spikingjelly.activation_based.ann2snn.examples.cnn_mnist.load_ann(device, checkpoint_path)[源代码]#
spikingjelly.activation_based.ann2snn.examples.cnn_mnist.download_checkpoint(checkpoint_url, checkpoint_path)[源代码]#
spikingjelly.activation_based.ann2snn.examples.cnn_mnist.convert_and_eval(recipe, device, ann_model, test_data_loader, time_steps)[源代码]#
spikingjelly.activation_based.ann2snn.examples.cnn_mnist.run_recipe_comparison(device, calibration_data_loader, test_data_loader, time_steps, checkpoint_path)[源代码]#
spikingjelly.activation_based.ann2snn.examples.cnn_mnist.run_legacy_mode_sweep(device, calibration_data_loader, test_data_loader, time_steps, checkpoint_path)[源代码]#
spikingjelly.activation_based.ann2snn.examples.cnn_mnist.main(args)[源代码]#

ResNet18 for CIFAR-10#

spikingjelly.activation_based.ann2snn.examples.resnet18_cifar10.val(net, device, data_loader, T=None)[源代码]#
spikingjelly.activation_based.ann2snn.examples.resnet18_cifar10.main(checkpoint_path='./SJ-cifar10-resnet18_model-sample.pth')[源代码]#

ImageNet ResNet-18 with LocalThresholdBalancingRecipe#

spikingjelly.activation_based.ann2snn.examples.imagenet_resnet18_ltb.parse_args()[源代码]#
spikingjelly.activation_based.ann2snn.examples.imagenet_resnet18_ltb.build_loaders(args, transform)[源代码]#
spikingjelly.activation_based.ann2snn.examples.imagenet_resnet18_ltb.accuracy(output, target, topk=(1, 5))[源代码]#
spikingjelly.activation_based.ann2snn.examples.imagenet_resnet18_ltb.evaluate_ann(model, data_loader, device)[源代码]#
spikingjelly.activation_based.ann2snn.examples.imagenet_resnet18_ltb.reset_snn(model)[源代码]#
spikingjelly.activation_based.ann2snn.examples.imagenet_resnet18_ltb.resolve_delay_start(model, data_loader, device, time_steps, delay_start)[源代码]#
spikingjelly.activation_based.ann2snn.examples.imagenet_resnet18_ltb.evaluate_snn(model, data_loader, device, time_steps, delay_start=0)[源代码]#
spikingjelly.activation_based.ann2snn.examples.imagenet_resnet18_ltb.make_model(weights)[源代码]#
spikingjelly.activation_based.ann2snn.examples.imagenet_resnet18_ltb.save_results(results, output_path)[源代码]#
spikingjelly.activation_based.ann2snn.examples.imagenet_resnet18_ltb.main()[源代码]#

ImageNet ViT-B/16 with STATransformerRecipe#

spikingjelly.activation_based.ann2snn.examples.imagenet_vit_sta.parse_args()[源代码]#
spikingjelly.activation_based.ann2snn.examples.imagenet_vit_sta.require_cuda(device)[源代码]#
spikingjelly.activation_based.ann2snn.examples.imagenet_vit_sta.build_loaders(args, transform)[源代码]#
spikingjelly.activation_based.ann2snn.examples.imagenet_vit_sta.accuracy(output, target, topk=(1, 5))[源代码]#
spikingjelly.activation_based.ann2snn.examples.imagenet_vit_sta.evaluate(model, data_loader, device, name)[源代码]#
spikingjelly.activation_based.ann2snn.examples.imagenet_vit_sta.make_first_real_then_zero_sequence(x, time_steps)[源代码]#
spikingjelly.activation_based.ann2snn.examples.imagenet_vit_sta.evaluate_sta(model, data_loader, device, name, time_steps)[源代码]#
spikingjelly.activation_based.ann2snn.examples.imagenet_vit_sta.format_scale_label(scale)[源代码]#
spikingjelly.activation_based.ann2snn.examples.imagenet_vit_sta.main()[源代码]#

BERT SST-2 with TransformerTDEquivalentRecipe#

spikingjelly.activation_based.ann2snn.examples.bert_sst2_transformer_td_equivalent.import_huggingface()[源代码]#
class spikingjelly.activation_based.ann2snn.examples.bert_sst2_transformer_td_equivalent.BertSST2FromEmbeddings(hf_model)[源代码]#

基类:Module

参数:

hf_model (Module)

forward(embedding_output, extended_attention_mask)[源代码]#
参数:
  • embedding_output (Tensor)

  • extended_attention_mask (Tensor)

返回类型:

Tensor

class spikingjelly.activation_based.ann2snn.examples.bert_sst2_transformer_td_equivalent.FXFriendlyBertSelfAttention(source, config)[源代码]#

基类:Module

参数:

source (Module)

transpose_for_scores(x)[源代码]#
参数:

x (Tensor)

返回类型:

Tensor

forward(hidden_states, extended_attention_mask)[源代码]#
参数:
返回类型:

Tensor

class spikingjelly.activation_based.ann2snn.examples.bert_sst2_transformer_td_equivalent.FXFriendlyBertAttention(source, config)[源代码]#

基类:Module

参数:

source (Module)

forward(hidden_states, extended_attention_mask)[源代码]#
参数:
返回类型:

Tensor

class spikingjelly.activation_based.ann2snn.examples.bert_sst2_transformer_td_equivalent.FXFriendlyBertLayer(source, config)[源代码]#

基类:Module

参数:

source (Module)

forward(hidden_states, extended_attention_mask)[源代码]#
参数:
返回类型:

Tensor

class spikingjelly.activation_based.ann2snn.examples.bert_sst2_transformer_td_equivalent.FXFriendlyBertEncoder(source, config)[源代码]#

基类:Module

参数:

source (Module)

forward(hidden_states, extended_attention_mask)[源代码]#
参数:
返回类型:

Tensor

spikingjelly.activation_based.ann2snn.examples.bert_sst2_transformer_td_equivalent.parse_args()[源代码]#
spikingjelly.activation_based.ann2snn.examples.bert_sst2_transformer_td_equivalent.collate_tokenized(batch, tokenizer, max_length)[源代码]#
spikingjelly.activation_based.ann2snn.examples.bert_sst2_transformer_td_equivalent.build_loader(args, tokenizer)[源代码]#
spikingjelly.activation_based.ann2snn.examples.bert_sst2_transformer_td_equivalent.make_embedding_batch(hf_model, batch, device)[源代码]#
spikingjelly.activation_based.ann2snn.examples.bert_sst2_transformer_td_equivalent.make_first_real_then_zero_sequence(x, time_steps)[源代码]#
spikingjelly.activation_based.ann2snn.examples.bert_sst2_transformer_td_equivalent.accuracy(logits, labels)[源代码]#
spikingjelly.activation_based.ann2snn.examples.bert_sst2_transformer_td_equivalent.evaluate_ann(wrapper, hf_model, loader, device, name)[源代码]#
spikingjelly.activation_based.ann2snn.examples.bert_sst2_transformer_td_equivalent.check_hf_wrapper_parity(wrapper, hf_model, loader, device, max_batches, atol)[源代码]#
spikingjelly.activation_based.ann2snn.examples.bert_sst2_transformer_td_equivalent.evaluate_transformer_td_equivalent(converted, hf_model, loader, device, time_steps, name)[源代码]#
spikingjelly.activation_based.ann2snn.examples.bert_sst2_transformer_td_equivalent.write_output(path, payload)[源代码]#
spikingjelly.activation_based.ann2snn.examples.bert_sst2_transformer_td_equivalent.main()[源代码]#

Synthetic RoBERTa QANN with SpikeZIPTFQANNRecipe#

class spikingjelly.activation_based.ann2snn.examples.roberta_spikezip_qann_synthetic.SpikeZIPQuantizer(level=8, sym=True, scale=0.25)[源代码]#

基类:Module

参数:
forward(x)[源代码]#
参数:

x (Tensor)

返回类型:

Tensor

class spikingjelly.activation_based.ann2snn.examples.roberta_spikezip_qann_synthetic.TinyQRobertaSelfAttention(hidden_size=16, num_heads=4, level=8)[源代码]#

基类:Module

参数:
  • hidden_size (int)

  • num_heads (int)

  • level (int)

transpose_for_scores(x)[源代码]#
参数:

x (Tensor)

返回类型:

Tensor

forward(hidden_states, attention_mask=None, head_mask=None, encoder_hidden_states=None, encoder_attention_mask=None, past_key_value=None, output_attentions=False)[源代码]#
参数:
class spikingjelly.activation_based.ann2snn.examples.roberta_spikezip_qann_synthetic.TinyQRobertaClassifier(vocab_size=32, hidden_size=16, num_heads=4, level=8)[源代码]#

基类:Module

参数:
  • vocab_size (int)

  • hidden_size (int)

  • num_heads (int)

  • level (int)

forward(tokens, attention_mask=None)[源代码]#
参数:
返回类型:

Tensor

spikingjelly.activation_based.ann2snn.examples.roberta_spikezip_qann_synthetic.parse_args()[源代码]#
spikingjelly.activation_based.ann2snn.examples.roberta_spikezip_qann_synthetic.write_output(path, payload)[源代码]#
spikingjelly.activation_based.ann2snn.examples.roberta_spikezip_qann_synthetic.collect_stbif_state(model)[源代码]#
参数:

model (Module)

spikingjelly.activation_based.ann2snn.examples.roberta_spikezip_qann_synthetic.main()[源代码]#