Analyze a Thinc model implementation. Includes checks for internal structure and activations during training. DOCS: https://spacy.io/api/cli#debug-model
(
# fmt: off
ctx: typer.Context, # This is only used to read additional arguments
config_path: Path = Arg(
..., help="Path to config file", exists=True, allow_dash=True
),
component: str = Arg(
..., help="Name of the pipeline component of which the model should be analysed"
),
layers: str = Opt(
"", "--layers", "-l", help="Comma-separated names of layer IDs to print"
),
dimensions: bool = Opt(False, "--dimensions", "-DIM", help="Show dimensions"),
parameters: bool = Opt(False, "--parameters", "-PAR", help="Show parameters"),
gradients: bool = Opt(False, "--gradients", "-GRAD", help="Show gradients"),
attributes: bool = Opt(False, "--attributes", "-ATTR", help="Show attributes"),
P0: bool = Opt(False, "--print-step0", "-P0", help="Print model before training"),
P1: bool = Opt(
False, "--print-step1", "-P1", help="Print model after initialization"
),
P2: bool = Opt(False, "--print-step2", "-P2", help="Print model after training"),
P3: bool = Opt(False, "--print-step3", "-P3", help="Print final predictions"),
use_gpu: int = Opt(-1, "--gpu-id", "-g", help="GPU ID or -1 for CPU"),
# fmt: on
)
| 34 | context_settings={"allow_extra_args": True, "ignore_unknown_options": True}, |
| 35 | ) |
| 36 | def debug_model_cli( |
| 37 | # fmt: off |
| 38 | ctx: typer.Context, # This is only used to read additional arguments |
| 39 | config_path: Path = Arg( |
| 40 | ..., help="Path to config file", exists=True, allow_dash=True |
| 41 | ), |
| 42 | component: str = Arg( |
| 43 | ..., help="Name of the pipeline component of which the model should be analysed" |
| 44 | ), |
| 45 | layers: str = Opt( |
| 46 | "", "--layers", "-l", help="Comma-separated names of layer IDs to print" |
| 47 | ), |
| 48 | dimensions: bool = Opt(False, "--dimensions", "-DIM", help="Show dimensions"), |
| 49 | parameters: bool = Opt(False, "--parameters", "-PAR", help="Show parameters"), |
| 50 | gradients: bool = Opt(False, "--gradients", "-GRAD", help="Show gradients"), |
| 51 | attributes: bool = Opt(False, "--attributes", "-ATTR", help="Show attributes"), |
| 52 | P0: bool = Opt(False, "--print-step0", "-P0", help="Print model before training"), |
| 53 | P1: bool = Opt( |
| 54 | False, "--print-step1", "-P1", help="Print model after initialization" |
| 55 | ), |
| 56 | P2: bool = Opt(False, "--print-step2", "-P2", help="Print model after training"), |
| 57 | P3: bool = Opt(False, "--print-step3", "-P3", help="Print final predictions"), |
| 58 | use_gpu: int = Opt(-1, "--gpu-id", "-g", help="GPU ID or -1 for CPU"), |
| 59 | # fmt: on |
| 60 | ): |
| 61 | """ |
| 62 | Analyze a Thinc model implementation. Includes checks for internal structure |
| 63 | and activations during training. |
| 64 | |
| 65 | DOCS: https://spacy.io/api/cli#debug-model |
| 66 | """ |
| 67 | setup_gpu(use_gpu) |
| 68 | layers = string_to_list(layers, intify=True) |
| 69 | print_settings = { |
| 70 | "dimensions": dimensions, |
| 71 | "parameters": parameters, |
| 72 | "gradients": gradients, |
| 73 | "attributes": attributes, |
| 74 | "layers": layers, |
| 75 | "print_before_training": P0, |
| 76 | "print_after_init": P1, |
| 77 | "print_after_training": P2, |
| 78 | "print_prediction": P3, |
| 79 | } |
| 80 | config_overrides = parse_config_overrides(ctx.args) |
| 81 | with show_validation_error(config_path): |
| 82 | raw_config = util.load_config( |
| 83 | config_path, overrides=config_overrides, interpolate=False |
| 84 | ) |
| 85 | config = raw_config.interpolate() |
| 86 | allocator = config["training"]["gpu_allocator"] |
| 87 | if use_gpu >= 0 and allocator: |
| 88 | set_gpu_allocator(allocator) |
| 89 | with show_validation_error(config_path): |
| 90 | nlp = util.load_model_from_config(raw_config) |
| 91 | config = nlp.config.interpolate() |
| 92 | T = registry.resolve(config["training"], schema=ConfigSchemaTraining) # type: ignore[arg-type] |
| 93 | seed = T["seed"] |
nothing calls this directly
no test coverage detected
searching dependent graphs…