shortcode(置顶)
贴一下可以玩的shortcode。
音乐播放
播放列表
夏日口袋专辑:
播放单曲
最爱的一首(我是紬厨):
视频播放
bilibili
有多P可以选择集数admonition
类型有:note、abstract、info、tip、success、question、warning、failure、danger、bug、example、quote。
贴一下可以玩的shortcode。
夏日口袋专辑:
最爱的一首(我是紬厨):
类型有:note、abstract、info、tip、success、question、warning、failure、danger、bug、example、quote。
= 'global'
a
def outer():
# def len(in_var):
# print('called my len() function: ', end="")
# l = 0
# for i in in_var:
# l += 1
# return l
= 'local'
a
def inner():
nonlocal a
+= ' variable'
a
inner()print('a is', a)
# print(len(a))
outer()
# print(len(a))
print('a is', a)
此时为nonlocal a,会按照local-闭包-global的顺序找到闭包变量a。a的值为local variable
python调试工具,类似于vscode的调试工具,使用命令行进行调试。
import pdb; pdb.set_trace()
或者
breakpoint()
python -m pdb [-c command] (-m module | pyfile) [args ...]
即help,可用命令如下
理论部分在这:generate相关 ## generate参数
def generate(
self,
= None,
inputs: Optional[torch.Tensor] = None,
generation_config: Optional[GenerationConfig] = None,
logits_processor: Optional[LogitsProcessorList] = None,
stopping_criteria: Optional[StoppingCriteriaList] int, torch.Tensor], List[int]]] = None,
prefix_allowed_tokens_fn: Optional[Callable[[bool] = None,
synced_gpus: Optional["PreTrainedModel"] = None,
assistant_model: Optional["BaseStreamer"] = None,
streamer: Optional[= None,
negative_prompt_ids: Optional[torch.Tensor] = None,
negative_prompt_attention_mask: Optional[torch.Tensor] **kwargs,
-> Union[GenerateOutput, torch.LongTensor]: )
在代码中可以看到在函数入口显式的定义了很多参数。他们的具体含义如下
einops.einsum calls einsum operations with einops-style named axes indexing, computing tensor products with an arbitrary number of tensors. Unlike typical einsum syntax, here you must pass tensors first, and then the pattern.
Also, note that rearrange operations such as
"(batch chan) out"
, or singleton axes()
, are not currently supported.
爱因斯坦求和
Packs several tensors into one. See einops tutorial for introduction into packing (and how it replaces stack and concatenation).
## unpack >Unpacks a single tensor into several by
splitting over a selected axes. See einops tutorial for introduction
into packing (and how it replaces stack and concatenation).
einops.rearrange is a reader-friendly smart element reordering for multidimensional tensors. This operation includes functionality of transpose (axes permutation), reshape (view), squeeze, unsqueeze, stack, concatenate and other operations.
代替reshape,给维度命名。可以用…代表不想动的维度。
einops.reduce combines rearrangement and reduction using reader-friendly notation.
reduce会使维度减少。
einops.repeat allows reordering elements and repeating them in arbitrary combinations. This operation includes functionality of repeat, tile, and broadcast functions.
repeat是使维度增加,与reduce相反。
## 应用
比如说repeat_kv函数就可以用einops.repeat很方便的实现