Skip to content

Improve config printing - #218

Open
esthermichelle wants to merge 4 commits into
pytorch-ignite:mainfrom
esthermichelle:improve-config-printing
Open

esthermichelle wants to merge 4 commits into
pytorch-ignite:mainfrom
esthermichelle:improve-config-printing

Conversation

@esthermichelle

Copy link
Copy Markdown
Contributor

Summary

This PR improves the string representation of ProjectConfig and closes #214.

This implementation uses Pydantic's built-in JSON serialization instead of introducing an additional dependency such as Rich.

A __str__ method was added to ProjectConfig that:

  • Returns the configuration as formatted JSON.
  • Uses an indentation of 2 spaces for better readability.
  • Preserves field aliases using by_alias=True, so fields such as _target_ are displayed correctly.

A test was added to tests/config/base_test.py to verify that:

  • The output is valid JSON.
  • The output is formatted across multiple lines.
  • Nested configuration fields are included.
  • Field aliases such as _target_ are preserved.

AI usage

  • No AI tools were used for this contribution
  • AI tools were used to assist this contribution

Tool(s) and usage:

Claude was used for code review and test suggestions.

Human Submission Confirmation

  • This PR was manually reviewed, committed, and submitted by a human contributor (not an automated agent)

Testing

  • Tests added or updated where needed
  • Existing tests and checks pass
  • Documentation updated if needed (Not required for this change)

Copilot AI balanced review requested due to automatic review settings November 17, 2026 15:31
@netlify

netlify Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

👷 Deploy request for trainite pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit aec179e

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The configuration string serialization remains incomplete because subclass-specific model and data fields can be omitted, and the existing test does not verify that those fields are preserved.

1 open issue

Review effort: Lite

Comment thread trainite/config/base.py Resolved
esthermichelle and others added 3 commits November 17, 2026 17:47
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@aaishwarymishra

Copy link
Copy Markdown
Member

can you give an example of how it's printed ?

@esthermichelle

Copy link
Copy Markdown
Contributor Author

Sure, here is an example showing the difference:

Before:

project_name='string-reverse' preprocessor=PreprocessorConfig(target='preprocessors.char_tokenizer.CharTokenizer', charset='@universal') model=ModelConfig(target='models.rope_transformer.RoPETransformerModel', collate_fn_target='models.rope_transformer.CausalLMCollateFn', hidden_size=64, num_layers=2, num_heads=2, feedforward_dim=128, dropout=0.1, max_seq_len=128) optimizer=OptimizerConfig(target='torch.optim.AdamW', lr=0.001) loss=LossConfig(target='torch.nn.CrossEntropyLoss', ignore_index=-100) data=DataWithAutoSplit(dataset=DatasetConfig(target='dataset_impl.string_reverse.StringReverseDataset', per_seq_size=256, charset='@alpha', min_seq_len=1, max_seq_len=16, seq_len=None, seed=42), transform=TransformConfig(target='dataset_impl.string_reverse.PromptCompletionTransform', ignore_index=-100), dataloader=DataLoaderConfig(batch_size=32, shuffle=True, num_workers=2), test_ratio=0.1, val_ratio=0.1) trainer=TrainerConfig(epochs=3, precision='float32', log_every_steps=10, early_stopping_patience=3, inference_every_epochs=None, inference_num_samples=5, max_inference_new_tokens=16, grad_clip_norm=None) output=OutputConfig(root='outputs', run_name='rope_transformer__string_reverse') logger='tensorboard' seed=42 device=None

After:

{
  "project_name": "string-reverse",
  "preprocessor": {
    "_target_": "preprocessors.char_tokenizer.CharTokenizer",
    "charset": "@universal"
  },
  "model": {
    "_target_": "models.rope_transformer.RoPETransformerModel",
    "collate_fn_target": "models.rope_transformer.CausalLMCollateFn",
    "hidden_size": 64,
    "num_layers": 2,
    "num_heads": 2,
    "feedforward_dim": 128,
    "dropout": 0.1,
    "max_seq_len": 128
  },
  "optimizer": {
    "_target_": "torch.optim.AdamW",
    "lr": 0.001
  },
  "loss": {
    "_target_": "torch.nn.CrossEntropyLoss",
    "ignore_index": -100
  },
  "data": {
    "dataset": {
      "_target_": "dataset_impl.string_reverse.StringReverseDataset",
      "per_seq_size": 256,
      "charset": "@alpha",
      "min_seq_len": 1,
      "max_seq_len": 16,
      "seq_len": null,
      "seed": 42
    },
    "transform": {
      "_target_": "dataset_impl.string_reverse.PromptCompletionTransform",
      "ignore_index": -100
    },
    "dataloader": {
      "batch_size": 32,
      "shuffle": true,
      "num_workers": 2
    },
    "test_ratio": 0.1,
    "val_ratio": 0.1
  },
  "trainer": {
    "epochs": 3,
    "precision": "float32",
    "log_every_steps": 10,
    "early_stopping_patience": 3,
    "inference_every_epochs": null,
    "inference_num_samples": 5,
    "max_inference_new_tokens": 16,
    "grad_clip_norm": null
  },
  "output": {
    "root": "outputs",
    "run_name": "rope_transformer__string_reverse"
  },
  "logger": "tensorboard",
  "seed": 42,
  "device": null
}

@aaishwarymishra

Copy link
Copy Markdown
Member

yeah, still looks off, I think it would be cleaner if we cab print it like yaml, I think we have pyyaml package and it can convert the config to yaml which then can be printed

this is what I used in my notebook example

print(yaml.safe_dump(dense_config.model_dump(by_alias=True), sort_keys=False, width=100).rstrip())

I mean you can simply it a bit if it works it was generated by an agent so not sure if we need to play with values like width etc.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve printing of config

3 participants