Skip to content

ClassificationTracer Class

ml_debugger.training.classification.classification_torchtracer.ClassificationTrainingTorchTracer

Bases: TrainingTracer, ClassificationTorchTracer

TrainingTracer for classification tasks using PyTorch models.

__init__(model, model_name, version_name, target_layers=None, additional_fields=None, additional_label_fields=None, auto_sync=False, force_table_recreate=False, api_endpoint=None, api_key=None)

Initialize classification tracer.

Parameters:

Name Type Description Default

model

Module

PyTorch model to trace.

required

model_name

str

Name of the ML model.

required

version_name

str

Version identifier for the ML model.

required

target_layers

Optional[Dict[str, str]]

Mapping of layer aliases to module paths.

None

additional_fields

Optional[List[dict]]

Extra fields for database schema.

None

additional_label_fields

Optional[List[dict]]

Extra fields for groundtruth database schema.

None

auto_sync

bool

Enable backgroup syncing of logged data.

False

force_table_recreate

bool

Whether to drop and recreate existing tables.

False

api_endpoint

Optional[str]

URL of the service API for data upload.

None

api_key

Optional[str]

API key for authenticating with the service.

None

__call__(model_input, ground_truth, input_ids, dataset_type='train', n_epoch=None, **kwargs)

Invoke the tracer on a single inference, recording I/O data.

Parameters:

Name Type Description Default

model_input

Any

Input data for the model inference.

required

ground_truth

Optional[Any]

Optional ground truth corresponding to input.

required

input_ids

List[str]

Identifiers of each input data.

required

dataset_type

str

Identifier of input dataset. (e.g. 'train', 'val', 'test', 'deploying')

'train'

n_epoch

Optional[int]

Number identifier of training iteration.

None

**kwargs

Any

Additional keyword arguments for parsing and saving I/O data. (will be passed to self._parse_and_save_io_data)

{}

Returns:

Name Type Description
Any Any

The raw output produced by the model.

Raises:

Type Description
Any

Propagates exceptions from parsing and saving operations.

get_hooked_features(layer_name)

Retrieve the captured output for a given layer alias.

Parameters:

Name Type Description Default

layer_name

str

Alias of the layer whose activation was captured.

required

Returns:

Name Type Description
Any Any

Activation data stored for the specified layer.

Raises:

Type Description
KeyError

If no activation has been captured for layer_name.

export(output_path=None, n_epoch=None)

Export extracted features and ground truth data into a ZIP archive.

Parameters:

Name Type Description Default

output_path

Optional[str]

Path or directory for saving the ZIP file. If no .zip extension, the default filename is appended. Defaults to cwd.

None

n_epoch

Optional[int]

Target epoch number. If None, exports all epochs.

None

Returns:

Type Description
Optional[Path]

Path to the created ZIP file, or None on non-primary distributed ranks.

wait_for_save(n_epoch=None, interval=3, *, force=False)

upload(n_epoch=None, *, force=False)

drop_epoch_data(n_epoch)

Delete cached rows scoped to a single epoch.

Parameters:

Name Type Description Default

n_epoch

int

削除対象の epoch 番号 (int 必須)。"None = 全件削除" と 取り違えるリスクを避けるため、本 API は int のみ受け付ける (Optional[int] ではない)。

required

Returns:

Type Description
Dict[str, int]

Dict[str, int]: {'extracted_feature': N, 'ground_truth': M} 形式の 削除行数。ground_truth が無い (logging_mode) 場合はキーが含まれない。

Raises:

Type Description
TypeError

n_epochint でない場合。

drop_version_data()

Drop all tables for the current (model, version) and recreate them empty.

既存の force_table_recreate=True 経路と同じ挙動を明示メソッドとして 提供する。内部的には __initialize_session(force_table_recreate=True) を 呼び直し、新しい repository / async batch writer を起動する。

Note

re-init 前に async_batch_writerflush() + stop() で完全停止 させてから session を再初期化する。これを怠ると daemon thread が旧 session を握ったまま残ってしまう。