semvec/pypi-packages huggingface dataset:
cli-options 0.2.1
Test about how to use typer to create a CLI with options
Requires Python: >=3.7

# `cli-options`

First package buid.

**Usage**:

```console
$ cli-options [OPTIONS] COMMAND [ARGS]...
```

**Options**:

* `--install-completion`: Install completion for the current shell.
* `--show-completion`: Show completion for the current shell, to copy it or customize the installation.
* `--help`: Show this message and exit.

**Commands**:

* `create`: Create a new user.
* `delete`: Delete a user.

## `cli-options create`

Create a new user.

**Usage**:

```console
$ cli-options create [OPTIONS] NAME
```

**Arguments**:

* `NAME`: [required]

**Options**:

* `--help`: Show this message and exit.

## `cli-options delete`

Delete a user.

**Usage**:

```console
$ cli-options delete [OPTIONS] NAME
```

**Arguments**:

* `NAME`: [required]

**Options**:

* `--help`: Show this message and exit.
batch-iter 0.1.1
Utilities for efficiently iterating over mini-batches of PyTorch tensors
Keywords: python, pytorch

# Pytorch batch iteration utilities

Utilities for iterating over mini-batches of tensors, while avoiding the overhead incurred by the significant DataLoader class when training light-weight models. 

Installing:

```bash
pip install batch-iter
```

The library is based on this [blog post](https://alexshtf.github.io/2024/08/31/BatchIter.html). There you can find more explanation and motivation. Below are simple examples:

## Plain iteration

```python
from batch_iter import BatchIter
import torch

X = torch.arange(15).reshape(5, 3)
y = torch.linspace(-1, 1, 5)

for Xb, yb in BatchIter(X, y, batch_size=2, shuffle=True):
  print('---')
  print('features = ', Xb)
  print('labels = ', yb)
```

The output is:

```
---
features =  tensor([[12, 13, 14],
        [ 6,  7,  8]])
labels =  tensor([1., 0.])
---
features =  tensor([[3, 4, 5],
        [0, 1, 2]])
labels =  tensor([-0.5000, -1.0000])
---
features =  tensor([[ 9, 10, 11]])
labels =  tensor([0.5000])
```

## Grouped iteration

The library also supports iterating over groups of tensors, identified by an additional group-id tensor. This is useful, for example, when training a ranking model, and we would like to iterate over mini-batches consisting of full queries. Each query is a group. 

For example:

```python
from batch_iter import GroupBatchIter
import torch

X = torch.arange(15).reshape(5, 3)
y = torch.linspace(-1, 1, 5)
# first three samples are a group with id 1, 
# the next two samples are another group with id 2.
group_id = torch.tensor([1, 1, 1, 2, 2])

for gb, Xb, yb in GroupBatchIter(group_id, X, y, batch_size=2, shuffle=True):
  print('---')
  print('group_id = ', gb)
  print('features = ', Xb)
  print('labels = ', yb)
```

The output is:

```
---
group_id =  tensor([1, 1, 1, 2, 2])
features =  tensor([[ 0,  1,  2],
        [ 3,  4,  5],
        [ 6,  7,  8],
        [ 9, 10, 11],
        [12, 13, 14]])
labels =  tensor([-1.0000, -0.5000,  0.0000,  0.5000,  1.0000])
```

The entire data-set is one mini-batch, since we chose a mini-batch of size two, meaning *two groups*.