-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Open
Description
Update Deprecated tensorflow.contrib.training.HParams Dependency
Problem Description
The current implementation uses the deprecated tensorflow.contrib.training.HParams which:
- Was removed in TensorFlow 2.x (as
tensorflow.contribwas fully deprecated) - Causes import errors for users with modern TensorFlow installations
- Forces users to downgrade to TF 1.x or install compatibility packages
Affected Code
In model.py:
from tensorflow.contrib.training import HParams # Line causing the error
def default_hparams():
return HParams(
n_vocab=0,
n_ctx=1024,
n_embd=768,
n_head=12,
n_layer=12,
)Suggested Solutions
Option 1: Native Python Implementation
class HParams:
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
def override_from_dict(self, params_dict):
self.__dict__.update(params_dict)
def default_hparams():
return HParams(
n_vocab=0,
n_ctx=1024,
n_embd=768,
n_head=12,
n_layer=12,
)Option 2: Use Dataclasses (Python 3.7+)
from dataclasses import dataclass
@dataclass
class HParams:
n_vocab: int = 0
n_ctx: int = 1024
n_embd: int = 768
n_head: int = 12
n_layer: int = 12
def override_from_dict(self, params_dict):
self.__dict__.update(params_dict)
def default_hparams():
return HParams()Option 3: Compatibility Backport
try:
from tensorflow.contrib.training import HParams # TF 1.x
except ImportError:
from hparams import HParams # Requires: pip install tensorflow-hparams
def default_hparams():
return HParams(
n_vocab=0,
n_ctx=1024,
n_embd=768,
n_head=12,
n_layer=12,
)Why This Change Matters
- Future Compatibility: TF 2.x is now standard and
contribwas officially removed - Easier Installation: Removes need for workarounds/downgrades
- Maintenance: Follows modern Python practices
- Performance: Native Python implementation has no TensorFlow dependency overhead
Workarounds (For Users)
Until this is merged, users can:
# Temporary solution 1: Downgrade TF
pip install tensorflow==1.15
# Temporary solution 2: Use backport
pip install tensorflow-hparamsReferences
Additional Notes
The change is backward-compatible as:
- The interface remains identical (
__dict__-based) - All existing
hparams.jsonloading continues working - No changes needed in other files that use
HParams
Metadata
Metadata
Assignees
Labels
No labels